some fun with db_new
This commit is contained in:
parent
c7f93d468e
commit
bc3f7984f5
1 changed files with 35 additions and 21 deletions
|
@ -14,8 +14,10 @@ from fastapi import FastAPI
|
|||
|
||||
from .config import Config, Settings
|
||||
from .db import Connection
|
||||
from .db.schemata import User
|
||||
from .db_new import capabilities, connection, user
|
||||
# from .db.schemata import User
|
||||
from .db_new import Capability
|
||||
from .db_new import Connection as Connection_new
|
||||
from .db_new import Device, User
|
||||
from .routers import main_router
|
||||
|
||||
settings = Settings.get()
|
||||
|
@ -47,31 +49,43 @@ async def on_startup() -> None:
|
|||
# connect to database
|
||||
Connection.connect(await current_config.db.db_engine)
|
||||
|
||||
# some testing
|
||||
with Connection.use() as db:
|
||||
print(User.from_db(db, "admin"))
|
||||
print(User.from_db(db, "nonexistent"))
|
||||
# # some testing
|
||||
# with Connection.use() as db:
|
||||
# print(User.from_db(db, "admin"))
|
||||
# print(User.from_db(db, "nonexistent"))
|
||||
|
||||
connection.Connection.connect("sqlite:///tmp/v2.db")
|
||||
Connection_new.connect("sqlite:///tmp/v2.db")
|
||||
|
||||
user.User.create(
|
||||
User.create(
|
||||
name="Uwe",
|
||||
password_clear="ulf",
|
||||
email="uwe@feh.de",
|
||||
)
|
||||
|
||||
print(user.User.get("Uwe"))
|
||||
print(user.User.authenticate("Uwe", "uwe"))
|
||||
print(User.get(name="Uwe"))
|
||||
print(User.authenticate("Uwe", "uwe"))
|
||||
|
||||
uwe = user.User.authenticate("Uwe", "ulf")
|
||||
uwe = User.authenticate("Uwe", "ulf")
|
||||
|
||||
uwe.extend_capabilities([capabilities.Capability.admin])
|
||||
uwe.set_capabilities([Capability.admin])
|
||||
uwe.update()
|
||||
print(uwe)
|
||||
print(uwe.get_capabilities())
|
||||
|
||||
uwe.remove_capabilities([capabilities.Capability.admin])
|
||||
uwe.set_capabilities([])
|
||||
uwe.update()
|
||||
print(uwe)
|
||||
print(uwe.get_capabilities())
|
||||
|
||||
with Connection_new.session as db:
|
||||
db.add(uwe)
|
||||
print(uwe.devices)
|
||||
|
||||
ipad = Device.create(
|
||||
owner_name="Uwe",
|
||||
name="iPad",
|
||||
type="tablet",
|
||||
)
|
||||
# ipad = Device.
|
||||
print(ipad)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
|
|
Loading…
Reference in a new issue