from fastlite import *
core
Bug demostration
= database(':memory:') db
"""
db.q(CREATE TABLE IF NOT EXISTS migrations (
id INTEGER PRIMARY KEY, name TEXT, inserted_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL
);
""")
[]
def list_records(): return db.q("SELECT * FROM migrations")
list_records()
[]
= db.t.migrations
migrations = migrations.dataclass() Migration
Creating Migration
with dataclass copies default value that is an SQL function:
= Migration(name='setup_db')
m m
Migrations(id=UNSET, name='setup_db', inserted_at='CURRENT_TIMESTAMP')
migrations.insert(m)
Migrations(id=1, name='setup_db', inserted_at='CURRENT_TIMESTAMP')
Inserting this record doesn’t execure the SQL function as expected:
list_records()
[{'id': 1, 'name': 'setup_db', 'inserted_at': 'CURRENT_TIMESTAMP'}]
Now let’s do a similar insert using raw SQL:db.q(“SELECT * FROM migrations”)
"INSERT INTO migrations (name) VALUES('create_users')") db.q(
[]
list_records()
[{'id': 1, 'name': 'setup_db', 'inserted_at': 'CURRENT_TIMESTAMP'},
{'id': 2, 'name': 'create_users', 'inserted_at': '2025-03-08 15:23:30'}]
As you can see, the SQL function got called as it should.