Skip to content

I have some questions since I'm a noobie #119

@JeysonFlores

Description

@JeysonFlores

I have 2 pieces of code, the one like the example of the README.md and the other the code that is on #113 . I have these questions:

  • How do I define the tables in order to make them compatible with the sqlite_tbl? Initially I thought that when I connect the DB and define the tables these tables would be created (like an ORM) but it seems like doesn't work like that. So, when I declare a "luatable" type in a column what type should I declare in the SQL definition? text, varchar or something else?

I have this code by the way

local sqlite = require 'sqlite'

local db = sqlite {
    uri = "db.sqlite",
    projects = {
        objectives = "luatable",
        title = { "text", unique = true, primary = true},
        created = { "timestamp", default = sqlite.lib.strftime("%s", "now") },
        done = "boolean"
    },
    todos = {
        id = true,
        title = "text",
        project = { "text", reference = "projects.title", on_delete = "cascade" }
    },
}

if db:exists("projects") == false then
    db:execute("create table projects")
end

and it gives me the following error:

luajit: /usr/local/share/lua/5.1/sqlite/stmt.lua:24: Invalid connection passed to sqlstmt:parse
stack traceback:
	[C]: in function 'assert'
	/usr/local/share/lua/5.1/sqlite/stmt.lua:24: in function 'parse'
	/usr/local/share/lua/5.1/sqlite/db.lua:249: in function 'eval'
	/usr/local/share/lua/5.1/sqlite/db.lua:324: in function 'exists'
	sq.lua:18: in main chunk
	[C]: at 0x56455f2641d0

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