skylark
skylark copied to clipboard
PrimaryKey is expected to be *an integer managed by the db* (rowid)
This is mostly a documentation issue/caveat, important mostly because of the surprises on first use. I expect this limitation to be a yet undocumented(?) design decision.
If there is no PrimaryKey
defined, then an id
field is implicitly expected to exist and is treated like a primary key, this implies, that it has to be defined in the database. (It is actually documented, yet surprising).
However some important existing tables do not have such a primary key field.
E.g. sqlite's sqlite_master
table has none defined explicitly, we can only assume a composite key of (type, name)
.
class SQLiteMaster(Model):
table_name = 'sqlite_master'
type = PrimaryKey()
name = PrimaryKey()
# skylark keeps track only of the last PrimaryKey, but it looks correct
# the important bit: need to define at least one PK
# otherwise skylark requires `id` to exist
def table_exists(table_name):
return SQLiteMaster.findone(type='table', name=table_name) is not None
When I have attempted to use UUID-s as primary keys (i.e. a string), the in-memory uuid
field has been silently overwritten by a short integer (rowid
)!
Hi, at first , this orm is long time no maintained, and there's no plan for forward development, the second, skylark is only designed for tables with primary keys.