8000 PrimaryKey is expected to be *an integer managed by the db* (rowid) · Issue #31 · hit9/skylark · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jan 24, 2018. It is now read-only.
This repository was archived by the owner on Jan 24, 2018. It is now read-only.
PrimaryKey is expected to be *an integer managed by the db* (rowid) #31
Open
@e3krisztian

Description

@e3krisztian

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0