DB

tiny db 기본 예제

개발자J군 2021. 11. 23. 11:17

tiny db 삽입, 검색, 업데이트, 삭제  (insert, search, update, delete)

from tinydb import TinyDB, Query

db=TinyDB('database_test.json')
User = Query()

def insert():  #디비 삽입
    db.insert({"name":"joo","data":[1]})
    db.insert({"name":"kim","data":[2]})

def search():  #검색
    result = db.search(User.name == "kim")
    print("결과",result)
    
def update():
    db.update({"data":[1,2]},User.name=="kim")

def delete():
    db.remove(User.name == "joo")
    
print(db.all())  #디비모두보기
반응형