Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JesperLundberg opened this issue Aug 14, 2024 · 1 comment
Open

Comments

@JesperLundberg
Copy link

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

@JesperLundberg
Copy link
Author

Small update.
I managed to create the table using execute from sqlite.lua but now I can't access that table. sqlite.lua has no idea of how that table looks or that it even exists.

I found a function called schema that seems like it could be used to get the "connection" to sqlite.lua but... Not quite it seems?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant