File size: 965 Bytes
ce351e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from deta import Deta  # pip3 install deta
import os
from dotenv import load_dotenv ## pip3 install python-dotenv

DETA_KEY = "c0zegv33efm_4MBTaoQAn76GzUfsZeKV64Uh9qMY3WZb"
# load_dotenv(".env")
# DETA_KEY = os.getenv("DETA_KEY")
# print(DETA_KEY)

deta = Deta(DETA_KEY)

# mybase is the name of the database in Deta. You can change it to any name you want.
db = deta.Base("mybase")
# print(db)

#* 目前我的mybase中有一個key是一个临时字符串。
def insert_user(username, name, password):
    return db.put({"key": username, "name": name, "password": password}) ## username is the key, a unique identifier.

def fetch_all_users():
    res = db.fetch()
    return res.items

all_users = fetch_all_users()
print(all_users)

def get_user(username):
    return db.get(username)

def update_user(username, name, password):
    return db.put({"key": username, "name": name, "password": password})

def delete_user(username):
    return db.delete(username)