kinda working
This commit is contained in:
113
internal/database/notes.sql.go
Normal file
113
internal/database/notes.sql.go
Normal file
@@ -0,0 +1,113 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.18.0
|
||||
// source: notes.sql
|
||||
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
const createNote = `-- name: CreateNote :exec
|
||||
INSERT INTO notes (id, created_at, updated_at, note, user_id)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
`
|
||||
|
||||
type CreateNoteParams struct {
|
||||
ID string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Note string
|
||||
UserID string
|
||||
}
|
||||
|
||||
func (q *Queries) CreateNote(ctx context.Context, arg CreateNoteParams) error {
|
||||
_, err := q.db.ExecContext(ctx, createNote,
|
||||
arg.ID,
|
||||
arg.CreatedAt,
|
||||
arg.UpdatedAt,
|
||||
arg.Note,
|
||||
arg.UserID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteNote = `-- name: DeleteNote :exec
|
||||
|
||||
DELETE FROM notes WHERE id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteNote(ctx context.Context, id string) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteNote, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getNote = `-- name: GetNote :one
|
||||
|
||||
SELECT id, created_at, updated_at, note, user_id FROM notes WHERE id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetNote(ctx context.Context, id string) (Note, error) {
|
||||
row := q.db.QueryRowContext(ctx, getNote, id)
|
||||
var i Note
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Note,
|
||||
&i.UserID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getNotesForUser = `-- name: GetNotesForUser :many
|
||||
|
||||
SELECT id, created_at, updated_at, note, user_id FROM notes WHERE user_id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetNotesForUser(ctx context.Context, userID string) ([]Note, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getNotesForUser, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Note
|
||||
for rows.Next() {
|
||||
var i Note
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Note,
|
||||
&i.UserID,
|
||||
); 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
|
||||
}
|
||||
|
||||
const updateNote = `-- name: UpdateNote :exec
|
||||
|
||||
UPDATE notes SET updated_at = ?, note = ? WHERE id = ?
|
||||
`
|
||||
|
||||
type UpdateNoteParams struct {
|
||||
UpdatedAt time.Time
|
||||
Note string
|
||||
ID string
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateNote(ctx context.Context, arg UpdateNoteParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateNote, arg.UpdatedAt, arg.Note, arg.ID)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user