Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e05e1c

Browse files
committed
new module for Feature #61
1 parent 8bab94d commit 2e05e1c

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

lib/core/replication.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import sqlite3
2+
3+
4+
class Replication:
5+
def __init__(self, dbpath):
6+
self.dbpath = dbpath
7+
self.connection = sqlite3.connect(dbpath)
8+
self.connection.isolation_level = None
9+
self.cursor = self.connection.cursor()
10+
11+
class DataType:
12+
def __init__(self, name):
13+
self.name = name
14+
15+
def __str__(self):
16+
return self.name
17+
18+
def __repr__(self):
19+
return "<DataType: %s>" % self
20+
21+
class Table:
22+
def __init__(self, parent, name, columns, typeless=False):
23+
self.parent = parent
24+
self.name = name
25+
self.columns = columns
26+
if not typeless:
27+
self.parent.cursor.execute('CREATE TABLE %s (%s)' % (name, ','.join('%s %s' % (colname, coltype) for colname, coltype in columns)))
28+
else:
29+
self.parent.cursor.execute('CREATE TABLE %s (%s)' % (name, ','.join(colname for colname in columns)))
30+
31+
def insert(self, rows):
32+
self.parent.cursor.executemany('INSERT INTO %s VALUES (?,?,?,?,?)' % self.name, rows)
33+
34+
35+
NULL = DataType('NULL')
36+
INTEGER = DataType('INTEGER')
37+
REAL = DataType('REAL')
38+
TEXT = DataType('TEXT')
39+
BLOB = DataType('BLOB')
40+
41+
def createTable(self, name, columns):
42+
return Table(self, name, columns)
43+
44+
def __del__(self):
45+
self.cursor.close()
46+
self.connection.close()
47+

0 commit comments

Comments
 (0)