def set(self, key, value): BaseTableHandler.execute( 'INSERT INTO properties (modified, key, value) VALUES(now(),%(key)s,%(value)s)' ' ON CONFLICT (key) DO UPDATE SET value=%(value)s', { 'key': key, 'value': value })
def set(self, lord, year, value): BaseTableHandler.execute( 'INSERT INTO marks (modified, lord, year, spec) VALUES(now(),%(lord)s,%(year)s,%(spec)s)' ' ON CONFLICT (lord, year, spec) DO UPDATE SET spec=%(spec)s', { 'lord': lord, 'year': year, 'spec': value })
def set_json(self, id, data): j = json.loads(data) BaseTableHandler.execute( "UPDATE characters SET modified=now(), data=%(data)s, name=%(name)s WHERE id=%(id)s", { 'id': id, 'name': j['name'], 'data': data })
def add(self, data): j = json.loads(data) BaseTableHandler.execute( "INSERT INTO characters (created, modified, data, name) VALUES (now(), now(), %(data)s, %(name)s)", { 'name': j['name'], 'data': data }, commit=True)
def set(self, lord, year, key, value): BaseTableHandler.execute( 'INSERT INTO lord (modified, lord, year, key, value) VALUES(now(),' ' %(lord)s, %(year)s, %(key)s, %(value)s)' ' ON CONFLICT (lord, year, key) DO UPDATE SET value=%(value)s', { 'lord': lord, 'year': year, 'key': key, 'value': value })
def list(self, lord=-1, year=-1): return BaseTableHandler.execute( 'SELECT * FROM marks WHERE (-1=%(lord)s::bigint OR lord=%(lord)s::bigint) AND (-1=%(year)s OR year=%(year)s) ORDER BY lord, year, spec', { 'lord': lord, 'year': year }, fetch='all')
def remove(self, key): BaseTableHandler.execute("DELETE FROM properties WHERE key=%s", param=[key], commit=True)
def get(self, key): return BaseTableHandler.execute( "SELECT * FROM properties WHERE key=%s", param=[key])
def list(self): return BaseTableHandler.execute( 'SELECT * FROM characters ORDER BY name', fetch='all')
def get_by_value(self, year, key, value): return BaseTableHandler.execute( "SELECT * FROM lord WHERE year=%s AND key = %s AND value=%s", param=[year, key, value])
def get_by_id(self, mid): return BaseTableHandler.execute( "SELECT * FROM characters WHERE id = %s", param=[mid], fetch='one')
def get_pcs(self): return BaseTableHandler.execute( "SELECT * FROM characters WHERE memberid IS NOT NULL", fetch='all')
def update(self, id, description, glory, year): return BaseTableHandler.execute('UPDATE events SET modified=now(), description=%s, glory=%s, year=%s WHERE id=%s', [description, glory, year, id], commit=True)
def glory(self, lord=0): return int(BaseTableHandler.execute('SELECT sum(glory) FROM events WHERE lord=%s::bigint', [lord], fetch='one')[0])
def get(self, lord, year, key): return BaseTableHandler.execute( "SELECT * FROM lord WHERE lord=%s, year=%s, key = %s", param=[lord, year, key])
def remove(self, id): return BaseTableHandler.execute('DELETE FROM events WHERE id=%s', [id], commit=True)
def get(self, lord, year): return BaseTableHandler.execute( "SELECT * FROM marks WHERE lord=%s, year=%s", [lord, year], fetch='all')
def remove(self, key): BaseTableHandler.execute("DELETE FROM marks WHERE id=%s", [int(key)])
def insert(self, lord, description, glory, year=-1): return BaseTableHandler.execute('INSERT INTO events (created, modified, year, lord, description, glory) ' 'VALUES(now(), now(),%s,%s,%s,%s);', [(self.year(), year)[year > 0], lord, description, glory], commit=True)
def list(self): return BaseTableHandler.execute( 'SELECT * FROM properties ORDER BY key', fetch='all')
def get_by_name(self, name): return BaseTableHandler.execute( f"SELECT * FROM characters WHERE name ILIKE '%{name}%'", fetch='one')
def remove(self, lord, year, key): BaseTableHandler.execute( "DELETE FROM properties WHERE lord=%s, year=%s, key=%s", param=[lord, year, key], commit=True)
def get(self, id): return BaseTableHandler.execute('SELECT * FROM events WHERE id=%s', [id], commit=True, fetch='one')