update data

This commit is contained in:
Johannes Jöns 2024-02-08 09:33:59 +01:00
parent 11871c8014
commit 71794010f5
3 changed files with 26 additions and 12 deletions

View file

@ -1,5 +1,3 @@
USE krautundrueben;
INSERT INTO KUNDE { INSERT INTO KUNDE {
KUNDENNR: 2001, KUNDENNR: 2001,
NACHNAME: 'Wellensteyn', NACHNAME: 'Wellensteyn',

View file

@ -1,19 +1,16 @@
import string import string
from dataclasses import fields from dataclasses import fields
from surrealdb import Surreal
import random import random
from lib.database import Database
from lib.datatypes import Customer from lib.datatypes import Customer
async def mainold(): async def mainold():
"""Example of how to use the SurrealDB client.""" db = await Database()
async with Surreal("ws://localhost:8000/rpc") as db:
await db.signin({"user": "root", "pass": "root"})
await db.use("test", "test")
for k in range(1, 20): for k in range(1, 20):
await db.create( db.create(
"Kunde", "Kunde",
fill_data().dict(), fill_data().dict(),
) )

19
lib/database.py Normal file
View file

@ -0,0 +1,19 @@
import os
from surrealdb import Surreal
from dotenv import load_dotenv
async def Database():
load_dotenv()
db = Surreal(f"ws://{os.environ.get('DB_HOST')}:{os.environ.get('DB_PORT')}/rpc")
await db.signin({"user": os.environ.get('DB_USER'), "pass": os.environ.get('DB_PW')})
await db.use("lf5", "krautundrueben")
return db
async def load_init_data():
db = await Database()
query = open('../data/data.surrealql', 'r').read()
await db.query(query)
return