Skip to content

How to create a table with composite primary key using sqlite.lua? #176

Description

@JesperLundberg

I'm trying to write a small scraping tool and I want to save based on the date and an identifier. So, for this a composite primary key is needed as I can have many rows with the same date and many rows with the same identifier but I want there to only be one for the combination of date and identifier.

I attempted:
date = { "date", unique = true, primary = true }, appid = { "number", unique = true, primary = true },
but I get the error about there being two primary keys in the same table (which makes sense).

I cannot find how to create a composite key using this library. Is it possible or is that out of scope and I need to do the below?


I could do it using the "execute sql" and providing an sql string but I prefer not if something else is possible.

The following sql should create a composite key:
CREATE TABLE something ( column1 INTEGER NOT NULL, column2 INTEGER NOT NULL, value, PRIMARY KEY ( column1, column2) );

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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