Skip to content

Can we use piccolo just as query builder? #814

Answered by dantownsend
danechitoaie asked this question in Q&A
Discussion options

You must be logged in to vote

Yeah, you can use it all in a single file if you want.

I use it like that quite a lot for scripts etc.

Here's an example:

import asyncio
from piccolo.engine.sqlite import SQLiteEngine
from piccolo.table import Table, create_db_tables
from piccolo.columns import Varchar

#########
# Define tables

# Define the engine for connecting to the database
DB = SQLiteEngine()

# Bind it explicitly to each Table, rather than using `piccolo_conf.py`
class MyTable(Table, db=DB):
    my_column = Varchar()

#########
# An example app using the query builder

app = FastAPI()

@app.get('/')
async def my_endpoint():
    return await MyTable.select()

#########
# Optionally create the database tables when t…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@danechitoaie
Comment options

@dantownsend
Comment options

@danechitoaie
Comment options

@dantownsend
Comment options

Answer selected by dantownsend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants