first db schema gen
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package database
|
||||
|
||||
//go:generate sqlc generate
|
||||
|
||||
type DB struct{}
|
||||
|
||||
func NewDB() (*DB, error) {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
-- name: GetAuthor :one
|
||||
SELECT * FROM recordings
|
||||
WHERE id = ? LIMIT 1;
|
||||
@@ -0,0 +1,4 @@
|
||||
CREATE TABLE artist_credit (
|
||||
id int PRIMARY KEY,
|
||||
text string NOT NULL
|
||||
);
|
||||
@@ -0,0 +1,5 @@
|
||||
CREATE TABLE artist_credit_artist (
|
||||
id int PRIMARY KEY,
|
||||
FOREIGN KEY(artist_id) REFERENCES artists(id),
|
||||
FOREIGN KEY(credit_id) REFERENCES artist_credit(id)
|
||||
);
|
||||
@@ -1,4 +1,4 @@
|
||||
CREATE TABLE artists (
|
||||
id INTEGER PRIMARY KEY,
|
||||
id int PRIMARY KEY,
|
||||
name text NOT NULL
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
CREATE TABLE audio_files (
|
||||
id uuid PRIMARY KEY,
|
||||
file_path text NOT NULL,
|
||||
file_type text NOT NULL,
|
||||
length_seconds int NOT NULL
|
||||
id int PRIMARY KEY,
|
||||
file_path text NOT NULL UNIQUE,
|
||||
length_milliseconds int NOT NULL,
|
||||
FOREIGN KEY(file_type_id) REFERENCES file_types(id),
|
||||
FOREIGN KEY(recording_id) REFERENCES recordings(id)
|
||||
);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE cover_art (
|
||||
id int PRIMARY KEY,
|
||||
is_embedded bool NOT NULL DEFAULT(false),
|
||||
file_path text NOT NULL,
|
||||
FOREIGN KEY(file_type_id) REFERENCES file_types(id)
|
||||
);
|
||||
@@ -1,4 +1,4 @@
|
||||
CREATE TABLE file_types (
|
||||
id INTEGER PRIMARY KEY,
|
||||
extension text NOT NULL
|
||||
extension text NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
CREATE TABLE recordings (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name text NOT NULL
|
||||
id int PRIMARY KEY,
|
||||
name text NOT NULL,
|
||||
FOREIGN KEY(artist_credit_id) REFERENCES artist_credit(id)
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE release_group_recordings (
|
||||
id int PRIMARY KEY,
|
||||
FOREIGN KEY(release_group_id) REFERENCES release_groups(id),
|
||||
FOREIGN KEY(recording_id) REFERENCES recordings(id)
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
CREATE TABLE release_groups (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name text NOT NULL
|
||||
id int PRIMARY KEY,
|
||||
name text NOT NULL,
|
||||
FOREIGN KEY(cover_art_id) REFERENCES cover_art(id)
|
||||
);
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.28.0
|
||||
|
||||
package sqlcgen
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
|
||||
PrepareContext(context.Context, string) (*sql.Stmt, error)
|
||||
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
|
||||
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.28.0
|
||||
|
||||
package sqlcgen
|
||||
|
||||
type Artist struct {
|
||||
ID int64
|
||||
Name string
|
||||
}
|
||||
|
||||
type ArtistCredit struct {
|
||||
ID int64
|
||||
Text interface{}
|
||||
}
|
||||
|
||||
type ArtistCreditArtist struct {
|
||||
ID int64
|
||||
}
|
||||
|
||||
type AudioFile struct {
|
||||
ID int64
|
||||
FilePath string
|
||||
LengthMilliseconds int64
|
||||
}
|
||||
|
||||
type CoverArt struct {
|
||||
ID int64
|
||||
IsEmbedded bool
|
||||
FilePath string
|
||||
}
|
||||
|
||||
type FileType struct {
|
||||
ID int64
|
||||
Extension string
|
||||
}
|
||||
|
||||
type Recording struct {
|
||||
ID int64
|
||||
Name string
|
||||
}
|
||||
|
||||
type ReleaseGroup struct {
|
||||
ID int64
|
||||
Name string
|
||||
}
|
||||
|
||||
type ReleaseGroupRecording struct {
|
||||
ID int64
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.28.0
|
||||
// source: recordings.sql
|
||||
|
||||
package sqlcgen
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const getAuthor = `-- name: GetAuthor :one
|
||||
SELECT id, name FROM recordings
|
||||
WHERE id = ? LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetAuthor(ctx context.Context, id int64) (Recording, error) {
|
||||
row := q.db.QueryRowContext(ctx, getAuthor, id)
|
||||
var i Recording
|
||||
err := row.Scan(&i.ID, &i.Name)
|
||||
return i, err
|
||||
}
|
||||
@@ -6,5 +6,5 @@ sql:
|
||||
schema: "./sql/schemas"
|
||||
gen:
|
||||
go:
|
||||
package: "sql"
|
||||
out: "sql"
|
||||
package: "sqlcgen"
|
||||
out: "./sql/sqlcgen"
|
||||
|
||||
Reference in New Issue
Block a user