-
Notifications
You must be signed in to change notification settings - Fork 95
Support for SQLite pragma and strict table settings #1187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We don't have a way of creating strict tables currently with Piccolo. Strict tables would be problematic for some of our column types (like If working from an existing database with strict tables it should work OK, as long as you keep to the narrower set of column types ( With PRAGMAs, we do currently set some: piccolo/piccolo/engine/sqlite.py Line 696 in 9517f49
We could extend this pretty easily to allow the user to specify their own PRAGMA statements. Presumably you would want to use this to enable strict mode.
Yes, exactly. It's just a problem with SQLite if you have multiple |
Hmm. I guess
I'm guessing you could switch it out for TypesMy main concern is catching types before they get added to the SQLite database, as it's far from type safe. I had my model setup in Peewee ORM but the My follow-up questions would be:
PRAGMAThat'd be super helpful to add support. So far I've been using Async
So it seems like better to just use |
Piccolo will not catch wrong types before inserting (we can insert Exampleimport asyncio
from piccolo.columns import Varchar, Array
from piccolo.table import Table, create_db_tables
from piccolo.utils.pydantic import create_pydantic_model
from piccolo.engine.sqlite import SQLiteEngine
from pydantic import BaseModel
DB = SQLiteEngine()
# Table example
class Manager(Table, db=DB):
name = Varchar()
arr_column = Array(base_column=Varchar())
# Models using Piccolo
ManagerModelIn = create_pydantic_model(table=Manager)
# Models using Pydantic
# class ManagerModelIn(BaseModel):
# name: str
# arr_column: list[str]
async def main():
# Table creating
await create_db_tables(Manager, if_not_exists=True)
# data = ManagerModelIn(name=1, arr_column=[1, 2])
# will raise ValidationError because we
# are using the wrong types (integer, not string)
data = ManagerModelIn(name="John", arr_column=["a", "b"]) # correct
manager = Manager(**data.model_dump())
await manager.save()
# select data
print(await Manager.select())
if __name__ == "__main__":
asyncio.run(main()) |
Apologies if this is somewhere in the documentation, but I can't find it. I'm looking for a replacement for Peewee (which has pragma and
strict_tables
support) that's async with FastAPI. Do you support these settings?Also, a little confused about this SQLite async page. Is this only relevant if you're running a
select
then aninsert
/update
/delete
(in that order?) — for example, if you were to run an insert first, then a select, within the same function, you can just follow the regular docs?The text was updated successfully, but these errors were encountered: