feat: Add name column to storagespace and update related queries

This commit is contained in:
garionion 2025-02-28 22:18:24 +01:00 committed by garionion (aider)
parent 86ee4f2ecb
commit ebbb2bac41
6 changed files with 49 additions and 6 deletions

View file

@ -124,6 +124,7 @@ type Storagespace struct {
ID int64
Parent sql.NullInt64
Location sql.NullString
Name string
}
type User struct {

View file

@ -175,8 +175,23 @@ func (q *Queries) CreateEvent(ctx context.Context, arg CreateEventParams) error
return err
}
const createStorageSpace = `-- name: CreateStorageSpace :exec
INSERT INTO storagespace (parent, location, name) VALUES (?, ?, ?)
`
type CreateStorageSpaceParams struct {
Parent sql.NullInt64
Location sql.NullString
Name string
}
func (q *Queries) CreateStorageSpace(ctx context.Context, arg CreateStorageSpaceParams) error {
_, err := q.db.ExecContext(ctx, createStorageSpace, arg.Parent, arg.Location, arg.Name)
return err
}
const getAllStorageSpaces = `-- name: GetAllStorageSpaces :many
SELECT id, parent, location FROM storagespace
SELECT id, parent, location, name FROM storagespace
`
func (q *Queries) GetAllStorageSpaces(ctx context.Context) ([]Storagespace, error) {
@ -188,7 +203,12 @@ func (q *Queries) GetAllStorageSpaces(ctx context.Context) ([]Storagespace, erro
var items []Storagespace
for rows.Next() {
var i Storagespace
if err := rows.Scan(&i.ID, &i.Parent, &i.Location); err != nil {
if err := rows.Scan(
&i.ID,
&i.Parent,
&i.Location,
&i.Name,
); err != nil {
return nil, err
}
items = append(items, i)
@ -230,7 +250,7 @@ func (q *Queries) GetAllUsers(ctx context.Context) ([]User, error) {
}
const getChildStorageSpaces = `-- name: GetChildStorageSpaces :many
SELECT id, parent, location FROM storagespace WHERE parent = ?
SELECT id, parent, location, name FROM storagespace WHERE parent = ?
`
func (q *Queries) GetChildStorageSpaces(ctx context.Context, parent sql.NullInt64) ([]Storagespace, error) {
@ -242,7 +262,12 @@ func (q *Queries) GetChildStorageSpaces(ctx context.Context, parent sql.NullInt6
var items []Storagespace
for rows.Next() {
var i Storagespace
if err := rows.Scan(&i.ID, &i.Parent, &i.Location); err != nil {
if err := rows.Scan(
&i.ID,
&i.Parent,
&i.Location,
&i.Name,
); err != nil {
return nil, err
}
items = append(items, i)
@ -463,13 +488,18 @@ func (q *Queries) GetObjectsInStorage(ctx context.Context, storageLocation sql.N
}
const getStorageSpaceByID = `-- name: GetStorageSpaceByID :one
SELECT id, parent, location FROM storagespace WHERE id = ?
SELECT id, parent, location, name FROM storagespace WHERE id = ?
`
func (q *Queries) GetStorageSpaceByID(ctx context.Context, id int64) (Storagespace, error) {
row := q.db.QueryRowContext(ctx, getStorageSpaceByID, id)
var i Storagespace
err := row.Scan(&i.ID, &i.Parent, &i.Location)
err := row.Scan(
&i.ID,
&i.Parent,
&i.Location,
&i.Name,
)
return i, err
}

View file

@ -0,0 +1,9 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE storagespace ADD COLUMN Name TEXT NOT NULL DEFAULT '';
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
ALTER TABLE storagespace DROP COLUMN Name;
-- +goose StatementEnd

View file

@ -28,6 +28,7 @@ CREATE TABLE storagespace
ID INTEGER PRIMARY KEY AUTOINCREMENT,
Parent INTEGER,
Location TEXT,
Name TEXT NOT NULL,
FOREIGN KEY (Parent) REFERENCES storagespace (ID)
);

View file

@ -8,6 +8,7 @@ export {}
declare module 'vue' {
export interface GlobalComponents {
AppFooter: typeof import('./components/AppFooter.vue')['default']
AppHeader: typeof import('./components/AppHeader.vue')['default']
HelloWorld: typeof import('./components/HelloWorld.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']

View file

@ -20,5 +20,6 @@ declare module 'vue-router/auto-routes' {
export interface RouteNamedMap {
'/': RouteRecordInfo<'/', '/', Record<never, never>, Record<never, never>>,
'/auth': RouteRecordInfo<'/auth', '/auth', Record<never, never>, Record<never, never>>,
'/storage': RouteRecordInfo<'/storage', '/storage', Record<never, never>, Record<never, never>>,
}
}