integrate prisma ORM not working #1092
-
Questioni have a little problem . i want to integrate flet with Orm Prisma . but it seems not working . is there something wrong with my `code``` Code samplemy code
main.py
from flet import *
import os
import asyncio
from prisma import Client
os.environ['PRISMA_DATASOURCES'] = 'default = mysql://root:[email protected]:3306/dbfood'
prisma = Client()
def main(page:Page):
nametxt = TextField(label="username")
agetxt = TextField(label="you age")
async def create_record(e):
try:
res = await prisma.user.create(
{"name": nametxt.value, "age": agetxt}
)
print("success",res)
except Exception as e:
print(e)
print("Error check !!!!")
page.add(
Column([
nametxt,
agetxt,
ElevatedButton("send ",
on_click=create_record
)
])
)
flet.app(target=main)
And my schema.prisma
datasource db {
provider = "mysql"
url = "mysql://root:[email protected]:3306/dbfood"
}
generator client {
provider = "prisma-client-py"
}
model User {
id Int @id @default(autoincrement())
name String
age Int
} Error messageRuntimeWarning: Enable tracemalloc to get the object allocation traceback
/usr/lib/python3.10/threading.py:953: RuntimeWarning: coroutine 'main.<locals>.create_record' was never awaited
self._target(*self._args, **self._kwargs)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 11 replies
-
Your |
Beta Was this translation helpful? Give feedback.
-
still not working and there is an error
|
Beta Was this translation helpful? Give feedback.
-
this also doesn't work
|
Beta Was this translation helpful? Give feedback.
-
and i have one more problem . why can't it be realtime. when added and edited and deleted the data. you have to reload the application again. usually I can use the clear() way on the widget . so no need to refresh to get the latest data.
|
Beta Was this translation helpful? Give feedback.
Your
main
method should be async too and in it you probably want to useadd_async()
instead ofadd()
. Try that and reply with the result.