skylark icon indicating copy to clipboard operation
skylark copied to clipboard

PrimaryKey is expected to be *an integer managed by the db* (rowid)

Open e3krisztian opened this issue 9 years ago • 1 comments

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)!

e3krisztian avatar Mar 23 '15 22:03 e3krisztian

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.

hit9 avatar Mar 28 '15 06:03 hit9