class Store: def __init__(self): self.db = Database() self.db.setup_db(domain_id, NAME_OF_DB) def close(self): try: self.db.close_db(domain_id, NAME_OF_DB) except KeyError: pass def read_user(self, name): rows = self.db.exec_sql(domain_id, NAME_OF_DB, 'select * from user_table where name=?', name) if len(rows) <= 0: return None return User.from_row(rows[0]) def setup(self): self.db.create_table_in_db(domain_id, NAME_OF_DB, 'user_table', certify_user_table_definition, primary_key=IDX_USER_ID, indices=[IDX_NAME]) def write_user(self, user): self.db.exec_sql(domain_id, NAME_OF_DB, 'insert into user_table values (?, ?, ?, ?)', user.user_id, user.name, user.keypair.public_key, user.keypair.private_key)
class Store: def __init__(self): self.db = Database() self.db.setup_db(domain_id, NAME_OF_DB) def close(self): self.db.close_db(domain_id, NAME_OF_DB) def get_shop_item(self, name): rows = self.db.exec_sql( domain_id, NAME_OF_DB, 'select item from shop_table where name=? and timestamp>=? ' + \ 'order by rowid desc', name, BASE_TIME ) if len(rows) <= 0: return None return rows[0][0] def get_shop_list(self, count=None): if count is not None: s_limit = ' limit {0}'.format(count) else: s_limit = '' rows = self.db.exec_sql( domain_id, NAME_OF_DB, 'select * from shop_table where timestamp>=?' + \ 'order by rowid desc' + s_limit, BASE_TIME ) dics = [] for row in rows: dics.append({ 'timestamp': row[IDX_TIMESTAMP], 'name': row[IDX_NAME], 'item': row[IDX_ITEM] }) return dics def setup(self): self.db.create_table_in_db(domain_id, NAME_OF_DB, 'shop_table', kmdmarche_shop_table_definition) def write_shop(self, timestamp, name, item): self.db.exec_sql(domain_id, NAME_OF_DB, 'insert into shop_table values (?, ?, ?)', timestamp, name, item)
def __init__(self): self.db = Database() self.db.setup_db(domain_id, NAME_OF_DB)
class Store: def __init__(self): self.db = Database() self.db.setup_db(domain_id, NAME_OF_DB) def close(self): self.db.close_db(domain_id, NAME_OF_DB) def get_tx_list(self, mint, name=None, count=None, offset=None, basetime=None): if basetime is None: basetime = 0 else: basetime = int(basetime) if offset is None: offset = 0 else: offset = int(offset) if count is not None: s_limit = ' limit {0}, {1}'.format(offset, count) else: s_limit = '' mint_id = mint.mint_id symbol = mint.get_currency_spec().symbol if name is not None: rows = self.db.exec_sql( domain_id, NAME_OF_DB, 'select * from tx_table where mint_id=? ' + \ 'and timestamp>=? ' + \ 'and (from_name=? or to_name=?) order by rowid desc' + s_limit, mint_id, basetime, name, name ) counts = self.db.exec_sql( domain_id, NAME_OF_DB, 'select count(*) from tx_table where mint_id=? ' + \ 'and timestamp>=? ' + \ 'and (from_name=? or to_name=?)', mint_id, basetime, name, name ) else: rows = self.db.exec_sql( domain_id, NAME_OF_DB, 'select * from tx_table where mint_id=? ' + \ 'and timestamp>=? ' + \ 'order by rowid desc' + s_limit, mint_id, basetime, ) counts = self.db.exec_sql( domain_id, NAME_OF_DB, 'select count(*) from tx_table where mint_id=? ' + \ 'and timestamp>=?', mint_id, basetime ) number = int(counts[0][0]) dics = [] for row in rows: dics.append({ 'timestamp': row[IDX_TIMESTAMP], 'from_name': row[IDX_FROM], 'to_name': row[IDX_TO], 'amount': row[IDX_AMOUNT], 'label': row[IDX_LABEL] }) return { 'count_before': offset, 'count_after': number - offset - len(rows), 'transactions': dics, 'symbol': symbol } def get_user(self, user_id, table): rows = self.db.exec_sql(domain_id, NAME_OF_DB, 'select * from ' + table + ' where user_id=?', user_id) if len(rows) <= 0: return None return User.from_row(rows[0]) def get_users(self, table): rows = self.db.exec_sql(domain_id, NAME_OF_DB, 'select * from ' + table) users = [] for row in rows: users.append(User.from_row(row)) return users def read_user(self, name, table): rows = self.db.exec_sql(domain_id, NAME_OF_DB, 'select * from ' + table + ' where name=?', name) if len(rows) <= 0: return None return User.from_row(rows[0]) def setup(self): self.db.create_table_in_db(domain_id, NAME_OF_DB, 'user_table', payment_user_table_definition, primary_key=IDX_USER_ID, indices=[IDX_NAME]) self.db.create_table_in_db(domain_id, NAME_OF_DB, 'currency_table', payment_user_table_definition, primary_key=IDX_USER_ID, indices=[IDX_NAME]) self.db.create_table_in_db(domain_id, NAME_OF_DB, 'tx_table', payment_tx_table_definition, primary_key=IDX_TX_ID, indices=[IDX_MINT_ID, IDX_FROM, IDX_TO]) def update_user(self, user, table): self.db.exec_sql( domain_id, NAME_OF_DB, 'update ' + table + ' set public_key=?, private_key=? ' + \ 'where user_id=?', user.keypair.public_key, user.keypair.private_key, user.user_id ) def user_exists(self, name, table): rows = self.db.exec_sql(domain_id, NAME_OF_DB, 'select rowid from ' + table + ' where name=?', name) return len(rows) > 0 def write_tx(self, tx_id, timestamp, mint_id, from_name, to_name, amount, label): self.db.exec_sql(domain_id, NAME_OF_DB, 'insert into tx_table values (?, ?, ?, ?, ?, ?, ?)', tx_id, timestamp, mint_id, from_name, to_name, amount, label) def write_user(self, user, table): self.db.exec_sql(domain_id, NAME_OF_DB, 'insert into ' + table + ' values (?, ?, ?, ?)', user.user_id, user.name, user.keypair.public_key, user.keypair.private_key)
def __init__(self, domain_id): self.domain_id = domain_id self.db = Database() self.db.setup_db(self.domain_id, NAME_OF_DB)
class Store: def __init__(self, domain_id): self.domain_id = domain_id self.db = Database() self.db.setup_db(self.domain_id, NAME_OF_DB) def close(self): self.db.close_db(self.domain_id, NAME_OF_DB) def get_user(self, user_id, table): rows = self.db.exec_sql(self.domain_id, NAME_OF_DB, 'select * from ' + table + ' where user_id=?', user_id) if len(rows) <= 0: return None return User.from_row(rows[0]) def get_users(self, table): rows = self.db.exec_sql(self.domain_id, NAME_OF_DB, 'select * from ' + table) return [User.from_row(row) for row in rows] def read_user(self, name, table): rows = self.db.exec_sql(self.domain_id, NAME_OF_DB, 'select * from ' + table + ' where name=?', name) if len(rows) <= 0: return None return User.from_row(rows[0]) def setup(self): self.db.create_table_in_db(self.domain_id, NAME_OF_DB, 'user_table', fileproof_user_table_definition, primary_key=IDX_USER_ID, indices=[IDX_NAME]) def update_keypair(self, user, table): self.db.exec_sql( self.domain_id, NAME_OF_DB, 'update ' + table + 'set public_key=?, private_key=? ' + \ 'where user_id=? and password=?', user.keypair.public_key, user.keypair.private_key, user.user_id, user.password ) def update_password(self, password, user, table): self.db.exec_sql( self.domain_id, NAME_OF_DB, 'update ' + table + 'set password=? where user_id=? and password=?', password, user.user_id, user.password) def user_exists(self, name, table): rows = self.db.exec_sql(self.domain_id, NAME_OF_DB, 'select rowid from ' + table + ' where name=?', name) return len(rows) > 0 def write_user(self, user, table): self.db.exec_sql(self.domain_id, NAME_OF_DB, 'insert into ' + table + ' values (?, ?, ?, ?, ?)', user.user_id, user.name, user.password, user.keypair.public_key, user.keypair.private_key)
class Store: def __init__(self): self.db = Database() self.db.setup_db(domain_id, NAME_OF_DB) def close(self): self.db.close_db(domain_id, NAME_OF_DB) def get_contribution_items(self, name): rows = self.db.exec_sql( domain_id, NAME_OF_DB, 'select item from contributions_table where name=? and ' + \ 'deleted=0 and good_until>=? and timestamp>=? ' + \ 'order by rowid desc', name, int(time.time()), BASE_TIME ) items = [] for row in rows: items.append(row[0]) return items def get_item_list(self, type='contributions', count=None): if count is not None: s_limit = ' limit {0}'.format(count) else: s_limit = '' rows = self.db.exec_sql( domain_id, NAME_OF_DB, 'select * from ' + type + '_table where deleted=0 and ' + \ 'good_until>=? and timestamp>=?' + \ 'order by rowid desc' + s_limit, int(time.time()), BASE_TIME ) dics = [] for row in rows: dics.append({ 'timestamp': row[IDX_TIMESTAMP], 'good_until': row[IDX_GOOD_UNTIL], 'name': row[IDX_NAME], 'item': row[IDX_ITEM] }) return dics def setup(self): self.db.create_table_in_db(domain_id, NAME_OF_DB, 'contributions_table', yuu_contributions_table_definition) self.db.create_table_in_db(domain_id, NAME_OF_DB, 'needs_table', yuu_needs_table_definition) def write_item(self, timestamp, good_until, name, item, type='contributions'): self.db.exec_sql( domain_id, NAME_OF_DB, 'insert into ' + type + '_table values (?, ?, ?, ?, ?)', timestamp, good_until, name, item, 0)