Getting started connecting to sqlite db #148
Unanswered
27concepts
asked this question in
Q&A
Replies: 1 comment 4 replies
|
Hey @27concepts, sorry to hear that. If you installed sqlite.lua then it the access part should be dealt with. Now, if you have a database filled with data, I suggest you first back it up, just in case anything goes wrong, or possibly of being locked due to write ops (see using sqlite with firefox database) There are two ways in which you can start communicating with database and all of theme are simple and straightforward : 1. quick and dirtyOpen the db, execute statements and close it local items = sqlite:with_open("/path/to/db", function(mydb)
-- see `: h sqlite_query_select` && `:h sqlite.db:select`
return mydb:select("tablename", { where = { key = "value" }})
-- just evaluate a sql statement
return db:eval("select * from tablename where x = ?", 1) --
end)2. structuredThis one is much more elegant, stable and super lazy, with auto closing local mydb = sqlite {
uri = "path/to/db",
tablename = {
-- ... keys and their types
}
}
local tablename = mydb.tablename
tablename:count() -- number of elementsNow you can see References:
Does this help? |
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi, I am lost as to how to get started here.
I have a sqlite db and I just want to query it. I am able to connect to it via DB Browser for SQLite, but no idea how to go about it using lua code.
I moved the sqlite folder in the same folder as my lua code and added local has_sqlite, sqlite = pcall(require, "sqlite") that I found in the other discussion. It doesn't work.
Help?
Thanks.
All reactions