Piccolo ORM Quickstart Guide
Creating a Database
To create a new database, you must add a new file into core/models/. The name should be descriptive of the module’s purpose (e.g., reminders.py).
In this file, define a Piccolo class Table. Be sure to set the following:
SQLiteEngine: This is the path to the SQLite database file. It will also be the file name. If the file does not yet exist, it will be created. (Need to check: It is relative to the program’s root path.)tablename: The name of the table itself. If not provided, Piccolo will convert the class name to snakecase.
[!NOTE] Be sure to include your newly created Table class to the list of all tables in
models/__init__.py.
You are ready to import your class to any cog.
Example: models/reminders.py
from piccolo.table import Table
from piccolo.columns import Integer, Text
from piccolo.engine.sqlite import SQLiteEngine
DB = SQLiteEngine(path="vor_reminders.db")
class Reminders(Table, db=DB, tablename="reminders"):
id: int = Serial(primary_key=True)
server_id: int = Integer()
user_id: int = Integer()
message: str = Text()
remind_at: int = Integer()
remind_from: int = Integer()
[!TIP] For autoincrementing identifier columns, use Serial rather than Integer to ensure sequential IDs. If a primary_key column is not present, Piccolo will create one of type Serial called “id”. Piccolo ORM Supported Column Types