aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pyapd/objects.py6
-rw-r--r--pyapd/stores/sqlite.py14
2 files changed, 15 insertions, 5 deletions
diff --git a/pyapd/objects.py b/pyapd/objects.py
index 2fa2e03..690c3f9 100644
--- a/pyapd/objects.py
+++ b/pyapd/objects.py
@@ -62,5 +62,11 @@ class Object():
def to_jsons(self):
return json.dumps(self.to_jsonable())
+ def __eq__(self, other):
+ for i in self.PROPERTIES:
+ if getattr(self, "ap_"+i, "") != getattr(other, "ap_"+i, ""):
+ return False
+ return True
+
def _generate_id(self):
raise NotImplementedError
diff --git a/pyapd/stores/sqlite.py b/pyapd/stores/sqlite.py
index a2a8145..54af554 100644
--- a/pyapd/stores/sqlite.py
+++ b/pyapd/stores/sqlite.py
@@ -13,9 +13,12 @@ class Store():
def add(self, obj: objects.Object):
obj_type = type(obj).__name__.lower()
c = self.db.cursor()
- # cur.execute("insert into pickled(data) values (?)", (sqlite3.Binary(pickle.dumps(p1, protocol=2)),))
- c.execute('insert or replace into objects(type, oid, obj) values ( :type, :oid, :obj )',
- (obj_type, obj.ap_id, sqlite3.Binary(pickle.dumps(obj, protocol=2))))
+ c.execute('''insert or replace
+ into objects(type, oid, obj)
+ values ( :type, :oid, :obj )''',
+ (obj_type, obj.ap_id, sqlite3.Binary(
+ pickle.dumps(obj, protocol=2)))
+ )
self.db.commit()
c.close()
@@ -26,7 +29,8 @@ class Store():
def get(self, obj_type: str, oid: str) -> objects.Object:
c = self.db.cursor()
c.execute(
- 'select obj from objects where type = :type and oid = :oid', (obj_type, oid))
+ 'select obj from objects'
+ ' where type = :type and oid = :oid', (obj_type, oid))
row = c.fetchone()
if row is None:
raise exceptions.DoesNotExist(
@@ -36,7 +40,7 @@ class Store():
def createdb(self):
c = self.db.cursor()
c.execute('create table objects(type text, oid text, obj blob)')
- c.execute('create index idx on objects(type, oid)')
+ c.execute('create unique index idx on objects(type, oid)')
if __name__ == '__main__':