diff options
author | Emile <git@emile.space> | 2025-02-12 22:05:22 +0100 |
---|---|---|
committer | Emile <git@emile.space> | 2025-02-12 22:05:22 +0100 |
commit | 7152205c80f059d3649e1830fb4dfc46d1fc158f (patch) | |
tree | b0d9a9aea760fabd61ee5cb06814d45cac5bb629 /nix/templates/goapp/frontend/db.go | |
parent | 4d08790c43b2d0720ef43b657a651a7c541d30d2 (diff) |
template: the goapp docker package should now (in theory) build
It's quite a weird way to pull out the packge name from the attribute set of defined packages, yet it kind of works. I can't test it, as docker doesn't want to run Mach-O binaries, but kicking this into hydra should result in some nice builds.
Diffstat (limited to 'nix/templates/goapp/frontend/db.go')
-rw-r--r-- | nix/templates/goapp/frontend/db.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/nix/templates/goapp/frontend/db.go b/nix/templates/goapp/frontend/db.go new file mode 100644 index 0000000..fd3605a --- /dev/null +++ b/nix/templates/goapp/frontend/db.go @@ -0,0 +1,37 @@ +package main + +import ( + "database/sql" + "log" + + _ "github.com/mattn/go-sqlite3" +) + +const create string = ` +CREATE TABLE IF NOT EXISTS users ( + id INTEGER NOT NULL PRIMARY KEY, + created_at DATETIME NOT NULL, + name TEXT, + passwordHash TEXT +); +` + +type State struct { + db *sql.DB // the database storing the "business data" + sessions *SqliteStore // the database storing sessions +} + +func NewState() (*State, error) { + db, err := sql.Open("sqlite3", databasePath) + if err != nil { + log.Println("Error opening the db: ", err) + return nil, err + } + if _, err := db.Exec(create); err != nil { + log.Println("Error creating the tables: ", err) + return nil, err + } + return &State{ + db: db, + }, nil +} |