snapshot of https://github.com/sqlc-dev/sqlc.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
This commit is contained in:
64
internal/goldeneye/analysis/analysis.go
Normal file
64
internal/goldeneye/analysis/analysis.go
Normal file
@@ -0,0 +1,64 @@
|
||||
// Package analysis is the shape of an engine's answer about a query: the
|
||||
// JSON `sqlc analyze` prints, so that a case's committed stdout.json can be
|
||||
// compared with what the database itself reports, byte for byte.
|
||||
package analysis
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// Query is what was found out about one query.
|
||||
type Query struct {
|
||||
Name string `json:"name"`
|
||||
Cmd string `json:"cmd"`
|
||||
Columns []Column `json:"columns"`
|
||||
Params []Param `json:"params"`
|
||||
}
|
||||
|
||||
// Column describes a result column, or the column a parameter stands in
|
||||
// for.
|
||||
type Column struct {
|
||||
Name string `json:"name"`
|
||||
Type *TypeExpr `json:"type,omitempty"`
|
||||
Table string `json:"table,omitempty"`
|
||||
}
|
||||
|
||||
// Param is one parameter and what it is compared with or assigned to.
|
||||
type Param struct {
|
||||
Number int `json:"number"`
|
||||
Column Column `json:"column"`
|
||||
}
|
||||
|
||||
// TypeExpr is a type as a call expression: a lowercased name applied to an
|
||||
// ordered argument list, each argument another type, an integer, a boolean
|
||||
// or a quoted string, optionally labelled. Nullability is an attribute of
|
||||
// the type rather than a wrapper.
|
||||
type TypeExpr struct {
|
||||
Name string `json:"name"`
|
||||
Nullable bool `json:"nullable,omitempty"`
|
||||
Args []TypeArg `json:"args,omitempty"`
|
||||
}
|
||||
|
||||
// TypeArg is one argument of a TypeExpr: a type, an integer, a boolean, a
|
||||
// quoted string, or an identifier — a bare word that is not a type, such as
|
||||
// the function an AggregateFunction names.
|
||||
type TypeArg struct {
|
||||
Label string `json:"label,omitempty"`
|
||||
Type *TypeExpr `json:"type,omitempty"`
|
||||
Int *int64 `json:"int,omitempty"`
|
||||
Bool *bool `json:"bool,omitempty"`
|
||||
String *string `json:"string,omitempty"`
|
||||
Ident *string `json:"ident,omitempty"`
|
||||
}
|
||||
|
||||
// Encode prints the answer the way sqlc analyze does.
|
||||
func Encode(queries []Query) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
enc := json.NewEncoder(&buf)
|
||||
enc.SetIndent("", " ")
|
||||
if err := enc.Encode(queries); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
Reference in New Issue
Block a user