diff --git a/.github/workflows/backend-lint.yaml b/.github/workflows/backend-lint.yaml index 330002ab..9b0ff912 100644 --- a/.github/workflows/backend-lint.yaml +++ b/.github/workflows/backend-lint.yaml @@ -26,18 +26,6 @@ jobs: with: go-version: "1.22" - - name: Install Task - uses: arduino/setup-task@v1 - with: - version: 3.x - repo-token: ${{ secrets.GITHUB_TOKEN }} - - - name: Install sqlc - run: go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest - - - name: Generate necessary backend code - run: task backend:generate - - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: diff --git a/backend/.gitignore b/backend/.gitignore index 9f33fdc9..8a177519 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -13,7 +13,7 @@ server *.test # Autogenerated files -/database/sqlc +# /database/sqlc # Output of the go coverage tool, specifically when used with LiteIDE *.out diff --git a/backend/database/sqlc/db.go b/backend/database/sqlc/db.go new file mode 100644 index 00000000..dacb52ec --- /dev/null +++ b/backend/database/sqlc/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.27.0 + +package database + +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, + } +} diff --git a/backend/database/sqlc/models.go b/backend/database/sqlc/models.go new file mode 100644 index 00000000..8663a439 --- /dev/null +++ b/backend/database/sqlc/models.go @@ -0,0 +1,20 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.27.0 + +package database + +import ( + "database/sql" +) + +type Album struct { + ID int64 + Name string + Bio sql.NullString +} + +type Test struct { + ID interface{} + CreatedAt sql.NullTime +} diff --git a/backend/database/sqlc/queries.sql.go b/backend/database/sqlc/queries.sql.go new file mode 100644 index 00000000..a21b7c7f --- /dev/null +++ b/backend/database/sqlc/queries.sql.go @@ -0,0 +1,64 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.27.0 +// source: queries.sql + +package database + +import ( + "context" +) + +const getAlbums = `-- name: GetAlbums :many +select id, name, bio from albums +` + +func (q *Queries) GetAlbums(ctx context.Context) ([]Album, error) { + rows, err := q.db.QueryContext(ctx, getAlbums) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Album + for rows.Next() { + var i Album + if err := rows.Scan(&i.ID, &i.Name, &i.Bio); 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 getTestData = `-- name: GetTestData :many +select id, created_at from test +` + +func (q *Queries) GetTestData(ctx context.Context) ([]Test, error) { + rows, err := q.db.QueryContext(ctx, getTestData) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Test + for rows.Next() { + var i Test + if err := rows.Scan(&i.ID, &i.CreatedAt); 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 +}