T
T
TanderOFF2021-08-07 00:36:38
Python
TanderOFF, 2021-08-07 00:36:38

How to add a new line?

Greetings, a small question:
There is a user base with an inv column, the inv column stores in itself:

{
    "item90": 12,
    "item3": 0,	
    "item60": 35,
    "item21": 15	
}


how to add a new line to this inv for all users so that it looks something like this:
{
    "item90": 12,
    "item3": 0,	
    "item60": 35,
    "item21": 15,
    "newstroke": 0	
}

Here's what I tried to do, but I don't know how to continue

await db.execute('UPDATE inv SET items = items + {} WHERE *'.format(arg))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2021-08-07
@TanderOFF

import sqlite3

con = sqlite3.connect(':memory:')
data = [
    ["item90", 12],
    ["item3", 0],	
    ["item60", 35],
    ["item21", 15]	
]
con.execute('''create table if not exists inv
            (items text, number integer)'''
            )

def print_db(con):
    for row in con.execute('select * from inv'):
        print(row)

def add_data(con, query, data):
    con.executemany(query, data)
    con.commit()

query = 'INSERT into inv values (?, ?)'

add_data(con, query, data)
print_db(con)

print('\nadd newstroke\n')
data = 
add_data(con, query, data)
print_db(con)

con.close()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question