initial commit
This commit is contained in:
132
db/queries.sql.go
Normal file
132
db/queries.sql.go
Normal file
@@ -0,0 +1,132 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: queries.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const deleteStaleFiles = `-- name: DeleteStaleFiles :exec
|
||||
DELETE FROM files WHERE path NOT IN (/*SLICE:paths*/?)
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteStaleFiles(ctx context.Context, paths []string) error {
|
||||
query := deleteStaleFiles
|
||||
var queryParams []interface{}
|
||||
if len(paths) > 0 {
|
||||
for _, v := range paths {
|
||||
queryParams = append(queryParams, v)
|
||||
}
|
||||
query = strings.Replace(query, "/*SLICE:paths*/?", strings.Repeat(",?", len(paths))[1:], 1)
|
||||
} else {
|
||||
query = strings.Replace(query, "/*SLICE:paths*/?", "NULL", 1)
|
||||
}
|
||||
_, err := q.db.ExecContext(ctx, query, queryParams...)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteSymbolsByFileID = `-- name: DeleteSymbolsByFileID :exec
|
||||
DELETE FROM symbols WHERE file_id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteSymbolsByFileID(ctx context.Context, fileID int64) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteSymbolsByFileID, fileID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getFileByPath = `-- name: GetFileByPath :one
|
||||
SELECT id, path, language, package, hash, indexed_at
|
||||
FROM files
|
||||
WHERE path = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetFileByPath(ctx context.Context, path string) (File, error) {
|
||||
row := q.db.QueryRowContext(ctx, getFileByPath, path)
|
||||
var i File
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Path,
|
||||
&i.Language,
|
||||
&i.Package,
|
||||
&i.Hash,
|
||||
&i.IndexedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertSymbol = `-- name: InsertSymbol :one
|
||||
INSERT INTO symbols (file_id, name, kind, line, line_end, col, col_end, exported, parent_id)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
type InsertSymbolParams struct {
|
||||
FileID int64
|
||||
Name string
|
||||
Kind string
|
||||
Line int64
|
||||
LineEnd sql.NullInt64
|
||||
Col sql.NullInt64
|
||||
ColEnd sql.NullInt64
|
||||
Exported sql.NullBool
|
||||
ParentID sql.NullInt64
|
||||
}
|
||||
|
||||
func (q *Queries) InsertSymbol(ctx context.Context, arg InsertSymbolParams) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, insertSymbol,
|
||||
arg.FileID,
|
||||
arg.Name,
|
||||
arg.Kind,
|
||||
arg.Line,
|
||||
arg.LineEnd,
|
||||
arg.Col,
|
||||
arg.ColEnd,
|
||||
arg.Exported,
|
||||
arg.ParentID,
|
||||
)
|
||||
var id int64
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const upsertFile = `-- name: UpsertFile :one
|
||||
INSERT INTO files (path, language, package, hash)
|
||||
VALUES (?, ?, ?, ?)
|
||||
ON CONFLICT(path) DO UPDATE SET
|
||||
language = excluded.language,
|
||||
package = excluded.package,
|
||||
hash = excluded.hash,
|
||||
indexed_at = CURRENT_TIMESTAMP
|
||||
RETURNING id, path, language, package, hash, indexed_at
|
||||
`
|
||||
|
||||
type UpsertFileParams struct {
|
||||
Path string
|
||||
Language string
|
||||
Package sql.NullString
|
||||
Hash string
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertFile(ctx context.Context, arg UpsertFileParams) (File, error) {
|
||||
row := q.db.QueryRowContext(ctx, upsertFile,
|
||||
arg.Path,
|
||||
arg.Language,
|
||||
arg.Package,
|
||||
arg.Hash,
|
||||
)
|
||||
var i File
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Path,
|
||||
&i.Language,
|
||||
&i.Package,
|
||||
&i.Hash,
|
||||
&i.IndexedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
Reference in New Issue
Block a user