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 {
KUNDENNR: 2001,
NACHNAME: 'Wellensteyn',

View file

@ -1,22 +1,19 @@
import string
from dataclasses import fields
from surrealdb import Surreal
import random
from lib.database import Database
from lib.datatypes import Customer
async def mainold():
"""Example of how to use the SurrealDB client."""
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):
await db.create(
"Kunde",
fill_data().dict(),
)
db = await Database()
for k in range(1, 20):
db.create(
"Kunde",
fill_data().dict(),
)
def randomword(length):

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