[{trans:1,trans:2},{trans:1,trans:2}
] - примерclass Database:
"""docstring for Database"""
def __init__(self, db_name):
self.connection = sqlite3.connect(db_name)
self.cursor = self.connection.cursor()
def add_user(self, user_id):
with self.connection:
def set_default(obj):
if isinstance(obj, set):
return list(obj)
raise TypeError
history = [{1,2},{3,4,5}]
self.cursor.execute("INSERT INTO `users` ('user_id','history') VALUES (?,?)", (user_id,history))
sell = self.cursor.execute("SELECT `history` FROM `users` WHERE `user_id` = ?", (user_id,)).fetchmany(1)
print(sell)
print(sell[0])
print(sell[0][1])
class Database:
"""docstring for Database"""
def __init__(self, db_name):
self.connection = sqlite3.connect(db_name)
self.cursor = self.connection.cursor()
def add_user(self, user_id):
with self.connection:
def set_default(obj):
if isinstance(obj, set):
return list(obj)
raise TypeError
history = json.dumps(list([{1,2},{3,4,5}]), default=set_default)
self.cursor.execute("INSERT INTO `users` ('user_id','history') VALUES (?,?)", (user_id,history))
sell = self.cursor.execute("SELECT `history` FROM `users` WHERE `user_id` = ?", (user_id,)).fetchmany(1)
print(sell)
print(sell[0][0])