+ baseline to the git

This commit is contained in:
Itsigo
2025-11-04 13:52:36 +01:00
commit b3193a10f9
29 changed files with 2079 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package database
import (
"context"
"database/sql"
_ "embed"
"log"
_ "github.com/mattn/go-sqlite3"
)
var (
dburl = "./data/data.db"
)
//go:embed schema.sql
var ddl string
func Init() *Queries {
ctx := context.Background()
db, err := sql.Open("sqlite3", dburl)
if err != nil {
log.Fatal(err)
}
if _, err := db.ExecContext(ctx, ddl); err != nil {
log.Fatal(err)
}
return New(db)
}

View File

@@ -0,0 +1,73 @@
-- name: ListMovies :many
SELECT * FROM movie
ORDER BY title ASC;
-- name: ListMovie :one
SELECT * FROM movie
WHERE id = ?;
-- name: ListWatchlist :many
SELECT * FROM movie
WHERE status = 0
ORDER BY
CASE WHEN streaming_services = '' OR streaming_services IS NULL THEN 1 ELSE 0 END,
title;
-- name: ListSettings :many
SELECT * FROM settings;
-- name: ListSetting :one
SELECT * FROM settings
WHERE id = ?;
-- name: ListSreamingServices :many
SELECT * FROM streaming_services;
-- name: CreateMovie :one
INSERT INTO movie (
title, original_title, imdbid, tmdbid, length, genre, streaming_services, director, year, watchcount, rating, status, owned, owned_type, ripped, review, overview
) VALUES (
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
)
RETURNING *;
-- name: AddSreamingService :exec
INSERT INTO streaming_services (title) VALUES ( ? );
-- name: DeleteSreamingService :exec
DELETE FROM streaming_services
WHERE id = ?;
-- name: DeleteMovie :exec
DELETE FROM movie
WHERE id = ?;
-- name: ChangeMovieStatus :exec
UPDATE movie
SET status = ?
WHERE id = ?;
-- name: ChangeMovieRating :exec
UPDATE movie
SET rating = ?
WHERE id = ?;
-- name: ChangeMovieOwned :exec
UPDATE movie
SET owned = ?, owned_type = ?
WHERE id = ?;
-- name: ChangeMovieStreamingServices :exec
UPDATE movie
SET streaming_services = ?
WHERE id = ?;
-- name: ChangeMovieRipped :exec
UPDATE movie
SET ripped = ?
WHERE id = ?;
-- name: ChangeSettingValue :exec
UPDATE settings
SET value = ?
WHERE id = ?;

View File

@@ -0,0 +1,51 @@
CREATE TABLE IF NOT EXISTS movie (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title VARCHAR(255) NOT NULL,
original_title VARCHAR(255) NOT NULL,
imdbid VARCHAR(25) NOT NULL,
tmdbid INTEGER NOT NULL,
length INTEGER NOT NULL,
genre VARCHAR(255) NOT NULL,
streaming_services VARCHAR(255) NOT NULL,
director VARCHAR(255) NOT NULL,
year VARCHAR(10) NOT NULL,
watchcount INTEGER NOT NULL,
rating INTEGER NOT NULL,
status INTEGER NOT NULL,
owned INTEGER NOT NULL,
owned_type VARCHAR(255) NOT NULL,
ripped INTEGER NOT NULL,
review TEXT NOT NULL,
overview TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS genres (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title VARCHAR(30) NOT NULL
);
CREATE TABLE IF NOT EXISTS streaming_services (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title VARCHAR(30) NOT NULL
);
CREATE TABLE IF NOT EXISTS settings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(100) NOT NULL,
value VARCHAR(100) NOT NULL,
description VARCHAR(255) NOT NULL
);
INSERT OR IGNORE INTO streaming_services
VALUES
("1", "Netflix"),
("2", "Disney Plus"),
("3", "Amazon Prime Video"),
("4", "Apple TV+");
INSERT OR IGNORE INTO settings
VALUES
("1", "HOME_GRID_VIEW", "false", "Grid or no grid on the Homepage"),
("2", "TMDB_API_KEY", "", "Your TMDB api key"),
("3", "REGION", "DE", "Your Region");