diff options
author | Diego Roversi <diego.roversi@gmail.com> | 2019-04-27 16:09:16 +0200 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2019-04-27 17:53:36 +0200 |
commit | 869117fe9019bb340c103189af8580f678ba522f (patch) | |
tree | 9d85eacd0a8b03ce9e103205f704dcecbb4c6dc0 | |
parent | 8ec9be0c8009b86affe588de774119c5f8e149fa (diff) |
fix formatting
-rw-r--r-- | pyapd/objects.py | 6 | ||||
-rw-r--r-- | pyapd/stores/sqlite.py | 14 |
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__': |