Database basic CRUD (#27)
* started schema * db schemas beginning * first db schema gen * added sqlc generation with go generate and sqlite driver * i think these dependencies are needed * added IF NOT EXISTS to create and CRUD for each table * fixed missing columns * added missing field * fixed code generation with sqlc
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.28.0
|
||||
// source: audio_files.sql
|
||||
|
||||
package sqlcgen
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const createAudioFile = `-- name: CreateAudioFile :one
|
||||
INSERT INTO audio_files (file_path, length_milliseconds, file_type_id, recording_id) VALUES (?, ?, ?, ?)
|
||||
RETURNING id, file_path, length_milliseconds, file_type_id, recording_id
|
||||
`
|
||||
|
||||
type CreateAudioFileParams struct {
|
||||
FilePath string
|
||||
LengthMilliseconds int64
|
||||
FileTypeID int64
|
||||
RecordingID int64
|
||||
}
|
||||
|
||||
func (q *Queries) CreateAudioFile(ctx context.Context, arg CreateAudioFileParams) (AudioFile, error) {
|
||||
row := q.db.QueryRowContext(ctx, createAudioFile,
|
||||
arg.FilePath,
|
||||
arg.LengthMilliseconds,
|
||||
arg.FileTypeID,
|
||||
arg.RecordingID,
|
||||
)
|
||||
var i AudioFile
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.FilePath,
|
||||
&i.LengthMilliseconds,
|
||||
&i.FileTypeID,
|
||||
&i.RecordingID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteAudioFile = `-- name: DeleteAudioFile :exec
|
||||
DELETE FROM audio_files
|
||||
WHERE id =?
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteAudioFile(ctx context.Context, id int64) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteAudioFile, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getAudioFile = `-- name: GetAudioFile :one
|
||||
SELECT id, file_path, length_milliseconds, file_type_id, recording_id FROM audio_files
|
||||
WHERE id = ? LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetAudioFile(ctx context.Context, id int64) (AudioFile, error) {
|
||||
row := q.db.QueryRowContext(ctx, getAudioFile, id)
|
||||
var i AudioFile
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.FilePath,
|
||||
&i.LengthMilliseconds,
|
||||
&i.FileTypeID,
|
||||
&i.RecordingID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateAudioFile = `-- name: UpdateAudioFile :exec
|
||||
UPDATE audio_files
|
||||
SET file_path = ?, length_milliseconds = ?, file_type_id = ?, recording_id = ?
|
||||
WHERE id =?
|
||||
`
|
||||
|
||||
type UpdateAudioFileParams struct {
|
||||
FilePath string
|
||||
LengthMilliseconds int64
|
||||
FileTypeID int64
|
||||
RecordingID int64
|
||||
ID int64
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateAudioFile(ctx context.Context, arg UpdateAudioFileParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateAudioFile,
|
||||
arg.FilePath,
|
||||
arg.LengthMilliseconds,
|
||||
arg.FileTypeID,
|
||||
arg.RecordingID,
|
||||
arg.ID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user