add files meta data
This commit is contained in:
@@ -0,0 +1,97 @@
|
|||||||
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// sqlc v1.31.1
|
||||||
|
// source: files.sql
|
||||||
|
|
||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
const createFile = `-- name: CreateFile :one
|
||||||
|
INSERT INTO files (
|
||||||
|
name,storage_key,checksum,created_at,updated_at,deleted_at
|
||||||
|
) VALUES (
|
||||||
|
?, ?, ?,date(),date(),date()
|
||||||
|
)
|
||||||
|
RETURNING id, name, storage_key, checksum, created_at, updated_at, deleted_at
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateFileParams struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
StorageKey string `json:"storage_key"`
|
||||||
|
Checksum sql.NullString `json:"checksum"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateFile(ctx context.Context, arg CreateFileParams) (File, error) {
|
||||||
|
row := q.db.QueryRowContext(ctx, createFile, arg.Name, arg.StorageKey, arg.Checksum)
|
||||||
|
var i File
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Name,
|
||||||
|
&i.StorageKey,
|
||||||
|
&i.Checksum,
|
||||||
|
&i.CreatedAt,
|
||||||
|
&i.UpdatedAt,
|
||||||
|
&i.DeletedAt,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const getFile = `-- name: GetFile :one
|
||||||
|
SELECT id, name, storage_key, checksum, created_at, updated_at, deleted_at FROM files
|
||||||
|
WHERE id = ? LIMIT 1
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetFile(ctx context.Context, id string) (File, error) {
|
||||||
|
row := q.db.QueryRowContext(ctx, getFile, id)
|
||||||
|
var i File
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Name,
|
||||||
|
&i.StorageKey,
|
||||||
|
&i.Checksum,
|
||||||
|
&i.CreatedAt,
|
||||||
|
&i.UpdatedAt,
|
||||||
|
&i.DeletedAt,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const listFiles = `-- name: ListFiles :many
|
||||||
|
SELECT id, name, storage_key, checksum, created_at, updated_at, deleted_at FROM files
|
||||||
|
ORDER BY name
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) ListFiles(ctx context.Context) ([]File, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, listFiles)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []File
|
||||||
|
for rows.Next() {
|
||||||
|
var i File
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Name,
|
||||||
|
&i.StorageKey,
|
||||||
|
&i.Checksum,
|
||||||
|
&i.CreatedAt,
|
||||||
|
&i.UpdatedAt,
|
||||||
|
&i.DeletedAt,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Close(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
@@ -1,4 +1,20 @@
|
|||||||
-- VaultDrop Schema
|
CREATE TABLE files (
|
||||||
-- Tables will be added here as the project evolves.
|
id TEXT PRIMARY KEY,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
storage_key TEXT NOT NULL,
|
||||||
|
checksum TEXT,
|
||||||
|
created_at INTEGER NOT NULL,
|
||||||
|
updated_at INTEGER NOT NULL,
|
||||||
|
deleted_at INTEGER
|
||||||
|
);
|
||||||
|
|
||||||
SELECT 1;
|
CREATE TABLE tags (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
name TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE file_tags (
|
||||||
|
file_id TEXT NOT NULL,
|
||||||
|
tag_id TEXT NOT NULL,
|
||||||
|
PRIMARY KEY (file_id, tag_id)
|
||||||
|
);
|
||||||
|
|||||||
@@ -3,3 +3,27 @@
|
|||||||
// sqlc v1.31.1
|
// sqlc v1.31.1
|
||||||
|
|
||||||
package db
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
type File struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
StorageKey string `json:"storage_key"`
|
||||||
|
Checksum sql.NullString `json:"checksum"`
|
||||||
|
CreatedAt int64 `json:"created_at"`
|
||||||
|
UpdatedAt int64 `json:"updated_at"`
|
||||||
|
DeletedAt sql.NullInt64 `json:"deleted_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type FileTag struct {
|
||||||
|
FileID string `json:"file_id"`
|
||||||
|
TagID string `json:"tag_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Tag struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
-- name: GetFile :one
|
||||||
|
SELECT * FROM files
|
||||||
|
WHERE id = ? LIMIT 1;
|
||||||
|
|
||||||
|
-- name: ListFiles :many
|
||||||
|
SELECT * FROM files
|
||||||
|
ORDER BY name;
|
||||||
|
|
||||||
|
-- name: CreateFile :one
|
||||||
|
INSERT INTO files (
|
||||||
|
name,storage_key,checksum,created_at,updated_at,deleted_at
|
||||||
|
) VALUES (
|
||||||
|
?, ?, ?,date(),date(),date()
|
||||||
|
)
|
||||||
|
RETURNING *;
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
-- name: GetHealth :one
|
|
||||||
SELECT 1 AS ok;
|
|
||||||
Reference in New Issue
Block a user