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

Skip to content

Commit 4ca1adb

Browse files
committed
update
1 parent 1ec5221 commit 4ca1adb

1 file changed

Lines changed: 41 additions & 6 deletions

File tree

lib/core/replication.py

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,23 @@
2626
import sqlite3
2727

2828
class Replication:
29+
"""
30+
This class holds all methods/classes used for database
31+
replication purposes.
32+
"""
33+
2934
def __init__(self, dbpath):
3035
self.dbpath = dbpath
3136
self.connection = sqlite3.connect(dbpath)
3237
self.connection.isolation_level = None
3338
self.cursor = self.connection.cursor()
3439

3540
class DataType:
41+
"""
42+
Using this class we define auxiliary objects
43+
used for representing sqlite data types.
44+
"""
45+
3646
def __init__(self, name):
3747
self.name = name
3848

@@ -43,6 +53,10 @@ def __repr__(self):
4353
return "<DataType: %s>" % self
4454

4555
class Table:
56+
"""
57+
This class defines methods used to manipulate table objects.
58+
"""
59+
4660
def __init__(self, parent, name, columns=None, create=True, typeless=False):
4761
self.parent = parent
4862
self.name = name
@@ -55,18 +69,39 @@ def __init__(self, parent, name, columns=None, create=True, typeless=False):
5569
self.parent.cursor.execute('CREATE TABLE %s (%s)' % (self.name, ','.join(colname for colname in self.columns)))
5670

5771
def insert(self, rows):
72+
"""
73+
This function is used for inserting row(s) into current table.
74+
"""
5875
self.parent.cursor.executemany('INSERT INTO %s VALUES (?,?,?,?,?)' % self.name, rows)
5976

77+
def select(self, condition=None):
78+
"""
79+
This function is used for selecting row(s) from current table.
80+
"""
81+
stmt = 'SELECT * FROM %s' % self.name
82+
if condition:
83+
stmt += 'WHERE %s' % condition
84+
return self.parent.cursor.execute(stmt)
6085

61-
NULL = DataType('NULL')
86+
# sqlite data types
87+
NULL = DataType('NULL')
6288
INTEGER = DataType('INTEGER')
63-
REAL = DataType('REAL')
64-
TEXT = DataType('TEXT')
65-
BLOB = DataType('BLOB')
89+
REAL = DataType('REAL')
90+
TEXT = DataType('TEXT')
91+
BLOB = DataType('BLOB')
6692

67-
def createTable(self, name, columns):
68-
return Table(self, name, columns)
93+
def createTable(self, tblname, columns=None):
94+
"""
95+
This function creates Table instance with current connection settings.
96+
"""
97+
return Table(self, tblname, columns)
6998

99+
def dropTable(self, tblname):
100+
"""
101+
This function drops table with given name using current connection.
102+
"""
103+
self.cursor.execute('DROP TABLE IF EXISTS %s' % tblname)
104+
70105
def __del__(self):
71106
self.cursor.close()
72107
self.connection.close()

0 commit comments

Comments
 (0)