diff --git a/internal/endtoend/testdata/builtins/go/db.go b/internal/endtoend/testdata/builtins/postgresql/go/db.go similarity index 100% rename from internal/endtoend/testdata/builtins/go/db.go rename to internal/endtoend/testdata/builtins/postgresql/go/db.go diff --git a/internal/endtoend/testdata/builtins/go/models.go b/internal/endtoend/testdata/builtins/postgresql/go/models.go similarity index 100% rename from internal/endtoend/testdata/builtins/go/models.go rename to internal/endtoend/testdata/builtins/postgresql/go/models.go diff --git a/internal/endtoend/testdata/builtins/query.sql b/internal/endtoend/testdata/builtins/postgresql/query.sql similarity index 100% rename from internal/endtoend/testdata/builtins/query.sql rename to internal/endtoend/testdata/builtins/postgresql/query.sql diff --git a/internal/endtoend/testdata/builtins/sqlc.json b/internal/endtoend/testdata/builtins/postgresql/sqlc.json similarity index 98% rename from internal/endtoend/testdata/builtins/sqlc.json rename to internal/endtoend/testdata/builtins/postgresql/sqlc.json index ac7c2ed829..bc05cb0384 100644 --- a/internal/endtoend/testdata/builtins/sqlc.json +++ b/internal/endtoend/testdata/builtins/postgresql/sqlc.json @@ -8,4 +8,4 @@ "queries": "query.sql" } ] -} +} \ No newline at end of file diff --git a/internal/endtoend/testdata/builtins/sqlite/go/aggfunc.sql.go b/internal/endtoend/testdata/builtins/sqlite/go/aggfunc.sql.go new file mode 100644 index 0000000000..9f7b87f8bf --- /dev/null +++ b/internal/endtoend/testdata/builtins/sqlite/go/aggfunc.sql.go @@ -0,0 +1,165 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.14.0 +// source: aggfunc.sql + +package querytest + +import ( + "context" + "database/sql" +) + +const getAvg = `-- name: GetAvg :one +SELECT avg(int_val) FROM test +` + +func (q *Queries) GetAvg(ctx context.Context) (sql.NullFloat64, error) { + row := q.db.QueryRowContext(ctx, getAvg) + var avg sql.NullFloat64 + err := row.Scan(&avg) + return avg, err +} + +const getCount = `-- name: GetCount :one +SELECT count(*) FROM test +` + +func (q *Queries) GetCount(ctx context.Context) (int64, error) { + row := q.db.QueryRowContext(ctx, getCount) + var count int64 + err := row.Scan(&count) + return count, err +} + +const getCountId = `-- name: GetCountId :one +SELECT count(id) FROM test +` + +func (q *Queries) GetCountId(ctx context.Context) (int64, error) { + row := q.db.QueryRowContext(ctx, getCountId) + var count int64 + err := row.Scan(&count) + return count, err +} + +const getGroupConcatInt = `-- name: GetGroupConcatInt :one +SELECT group_concat(int_val) FROM test +` + +func (q *Queries) GetGroupConcatInt(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getGroupConcatInt) + var group_concat string + err := row.Scan(&group_concat) + return group_concat, err +} + +const getGroupConcatInt2 = `-- name: GetGroupConcatInt2 :one +SELECT group_concat(1, ':') FROM test +` + +func (q *Queries) GetGroupConcatInt2(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getGroupConcatInt2) + var group_concat string + err := row.Scan(&group_concat) + return group_concat, err +} + +const getGroupConcatText = `-- name: GetGroupConcatText :one +SELECT group_concat(text_val) FROM test +` + +func (q *Queries) GetGroupConcatText(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getGroupConcatText) + var group_concat string + err := row.Scan(&group_concat) + return group_concat, err +} + +const getGroupConcatText2 = `-- name: GetGroupConcatText2 :one +SELECT group_concat(text_val, ':') FROM test +` + +func (q *Queries) GetGroupConcatText2(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getGroupConcatText2) + var group_concat string + err := row.Scan(&group_concat) + return group_concat, err +} + +const getMaxInt = `-- name: GetMaxInt :one +SELECT max(int_val) FROM test +` + +func (q *Queries) GetMaxInt(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, getMaxInt) + var max interface{} + err := row.Scan(&max) + return max, err +} + +const getMaxText = `-- name: GetMaxText :one +SELECT max(text_val) FROM test +` + +func (q *Queries) GetMaxText(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, getMaxText) + var max interface{} + err := row.Scan(&max) + return max, err +} + +const getMinInt = `-- name: GetMinInt :one +SELECT min(int_val) FROM test +` + +func (q *Queries) GetMinInt(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, getMinInt) + var min interface{} + err := row.Scan(&min) + return min, err +} + +const getMinText = `-- name: GetMinText :one +SELECT min(text_val) FROM test +` + +func (q *Queries) GetMinText(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, getMinText) + var min interface{} + err := row.Scan(&min) + return min, err +} + +const getSumInt = `-- name: GetSumInt :one +SELECT sum(int_val) FROM test +` + +func (q *Queries) GetSumInt(ctx context.Context) (sql.NullFloat64, error) { + row := q.db.QueryRowContext(ctx, getSumInt) + var sum sql.NullFloat64 + err := row.Scan(&sum) + return sum, err +} + +const getSumText = `-- name: GetSumText :one +SELECT sum(text_val) FROM test +` + +func (q *Queries) GetSumText(ctx context.Context) (sql.NullFloat64, error) { + row := q.db.QueryRowContext(ctx, getSumText) + var sum sql.NullFloat64 + err := row.Scan(&sum) + return sum, err +} + +const getTotalInt = `-- name: GetTotalInt :one +SELECT total(int_val) FROM test +` + +func (q *Queries) GetTotalInt(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getTotalInt) + var total float64 + err := row.Scan(&total) + return total, err +} diff --git a/internal/endtoend/testdata/builtins/sqlite/go/db.go b/internal/endtoend/testdata/builtins/sqlite/go/db.go new file mode 100644 index 0000000000..19557a6a5a --- /dev/null +++ b/internal/endtoend/testdata/builtins/sqlite/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.14.0 + +package querytest + +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/internal/endtoend/testdata/builtins/sqlite/go/mathfunc.sql.go b/internal/endtoend/testdata/builtins/sqlite/go/mathfunc.sql.go new file mode 100644 index 0000000000..e0b281b875 --- /dev/null +++ b/internal/endtoend/testdata/builtins/sqlite/go/mathfunc.sql.go @@ -0,0 +1,329 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.14.0 +// source: mathfunc.sql + +package querytest + +import ( + "context" +) + +const getAcos = `-- name: GetAcos :one +select acos(1.0) +` + +func (q *Queries) GetAcos(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getAcos) + var acos float64 + err := row.Scan(&acos) + return acos, err +} + +const getAcosh = `-- name: GetAcosh :one +select acosh(1.0) +` + +func (q *Queries) GetAcosh(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getAcosh) + var acosh float64 + err := row.Scan(&acosh) + return acosh, err +} + +const getAsin = `-- name: GetAsin :one +select asin(1.0) +` + +func (q *Queries) GetAsin(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getAsin) + var asin float64 + err := row.Scan(&asin) + return asin, err +} + +const getAsinh = `-- name: GetAsinh :one +select asinh(1.0) +` + +func (q *Queries) GetAsinh(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getAsinh) + var asinh float64 + err := row.Scan(&asinh) + return asinh, err +} + +const getAtan = `-- name: GetAtan :one +select atan(1.0) +` + +func (q *Queries) GetAtan(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getAtan) + var atan float64 + err := row.Scan(&atan) + return atan, err +} + +const getAtan2 = `-- name: GetAtan2 :one +select atan2(1.0, 0.5) +` + +func (q *Queries) GetAtan2(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getAtan2) + var atan2 float64 + err := row.Scan(&atan2) + return atan2, err +} + +const getAtanh = `-- name: GetAtanh :one +select atanh(1.0) +` + +func (q *Queries) GetAtanh(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getAtanh) + var atanh float64 + err := row.Scan(&atanh) + return atanh, err +} + +const getCeil = `-- name: GetCeil :one +select ceil(1.0) +` + +func (q *Queries) GetCeil(ctx context.Context) (int64, error) { + row := q.db.QueryRowContext(ctx, getCeil) + var ceil int64 + err := row.Scan(&ceil) + return ceil, err +} + +const getCeilin = `-- name: GetCeilin :one +select ceiling(1.0) +` + +func (q *Queries) GetCeilin(ctx context.Context) (int64, error) { + row := q.db.QueryRowContext(ctx, getCeilin) + var ceiling int64 + err := row.Scan(&ceiling) + return ceiling, err +} + +const getCos = `-- name: GetCos :one +select cos(1.0) +` + +func (q *Queries) GetCos(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getCos) + var cos float64 + err := row.Scan(&cos) + return cos, err +} + +const getCosh = `-- name: GetCosh :one +select cosh(1.0) +` + +func (q *Queries) GetCosh(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getCosh) + var cosh float64 + err := row.Scan(&cosh) + return cosh, err +} + +const getDegrees = `-- name: GetDegrees :one +select degrees(1.0) +` + +func (q *Queries) GetDegrees(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getDegrees) + var degrees float64 + err := row.Scan(°rees) + return degrees, err +} + +const getExp = `-- name: GetExp :one +select exp(1.0) +` + +func (q *Queries) GetExp(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getExp) + var exp float64 + err := row.Scan(&exp) + return exp, err +} + +const getFloor = `-- name: GetFloor :one +select floor(1.0) +` + +func (q *Queries) GetFloor(ctx context.Context) (int64, error) { + row := q.db.QueryRowContext(ctx, getFloor) + var floor int64 + err := row.Scan(&floor) + return floor, err +} + +const getLn = `-- name: GetLn :one +select ln(1.0) +` + +func (q *Queries) GetLn(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getLn) + var ln float64 + err := row.Scan(&ln) + return ln, err +} + +const getLog = `-- name: GetLog :one +select log(1.0) +` + +func (q *Queries) GetLog(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getLog) + var log float64 + err := row.Scan(&log) + return log, err +} + +const getLog10 = `-- name: GetLog10 :one +select log10(1.0) +` + +func (q *Queries) GetLog10(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getLog10) + var log10 float64 + err := row.Scan(&log10) + return log10, err +} + +const getLog2 = `-- name: GetLog2 :one +select log2(1.0) +` + +func (q *Queries) GetLog2(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getLog2) + var log2 float64 + err := row.Scan(&log2) + return log2, err +} + +const getLogBase = `-- name: GetLogBase :one +select log(1.0, 2.0) +` + +func (q *Queries) GetLogBase(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getLogBase) + var log float64 + err := row.Scan(&log) + return log, err +} + +const getMod = `-- name: GetMod :one +select mod(1, 2) +` + +func (q *Queries) GetMod(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getMod) + var mod float64 + err := row.Scan(&mod) + return mod, err +} + +const getPi = `-- name: GetPi :one +select pi() +` + +func (q *Queries) GetPi(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getPi) + var pi float64 + err := row.Scan(&pi) + return pi, err +} + +const getPow = `-- name: GetPow :one +select pow(1, 2) +` + +func (q *Queries) GetPow(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getPow) + var pow float64 + err := row.Scan(&pow) + return pow, err +} + +const getPower = `-- name: GetPower :one +select power(1, 2) +` + +func (q *Queries) GetPower(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getPower) + var power float64 + err := row.Scan(&power) + return power, err +} + +const getRadians = `-- name: GetRadians :one +select radians(1) +` + +func (q *Queries) GetRadians(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getRadians) + var radians float64 + err := row.Scan(&radians) + return radians, err +} + +const getSin = `-- name: GetSin :one +select sin(1.0) +` + +func (q *Queries) GetSin(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getSin) + var sin float64 + err := row.Scan(&sin) + return sin, err +} + +const getSinh = `-- name: GetSinh :one +select sinh(1.0) +` + +func (q *Queries) GetSinh(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getSinh) + var sinh float64 + err := row.Scan(&sinh) + return sinh, err +} + +const getSqrt = `-- name: GetSqrt :one +select sqrt(1.0) +` + +func (q *Queries) GetSqrt(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getSqrt) + var sqrt float64 + err := row.Scan(&sqrt) + return sqrt, err +} + +const getTan = `-- name: GetTan :one +select tan(1.0) +` + +func (q *Queries) GetTan(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getTan) + var tan float64 + err := row.Scan(&tan) + return tan, err +} + +const getTrunc = `-- name: GetTrunc :one +select trunc(1.0) +` + +func (q *Queries) GetTrunc(ctx context.Context) (int64, error) { + row := q.db.QueryRowContext(ctx, getTrunc) + var trunc int64 + err := row.Scan(&trunc) + return trunc, err +} diff --git a/internal/endtoend/testdata/builtins/sqlite/go/models.go b/internal/endtoend/testdata/builtins/sqlite/go/models.go new file mode 100644 index 0000000000..ca05f9955f --- /dev/null +++ b/internal/endtoend/testdata/builtins/sqlite/go/models.go @@ -0,0 +1,13 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.14.0 + +package querytest + +import () + +type Test struct { + ID int64 + IntVal int64 + TextVal string +} diff --git a/internal/endtoend/testdata/builtins/sqlite/go/scalarfunc.sql.go b/internal/endtoend/testdata/builtins/sqlite/go/scalarfunc.sql.go new file mode 100644 index 0000000000..93b74c2f5f --- /dev/null +++ b/internal/endtoend/testdata/builtins/sqlite/go/scalarfunc.sql.go @@ -0,0 +1,574 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.14.0 +// source: scalarfunc.sql + +package querytest + +import ( + "context" + "database/sql" + + "github.com/lib/pq" +) + +const getAbs = `-- name: GetAbs :one +SELECT abs(int_val) FROM test +` + +func (q *Queries) GetAbs(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getAbs) + var abs float64 + err := row.Scan(&abs) + return abs, err +} + +const getChanges = `-- name: GetChanges :one +SELECT changes() +` + +func (q *Queries) GetChanges(ctx context.Context) (int64, error) { + row := q.db.QueryRowContext(ctx, getChanges) + var changes int64 + err := row.Scan(&changes) + return changes, err +} + +const getChar1 = `-- name: GetChar1 :one +SELECT char(65) +` + +func (q *Queries) GetChar1(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getChar1) + var char string + err := row.Scan(&char) + return char, err +} + +const getChar3 = `-- name: GetChar3 :one +SELECT char(65, 66, 67) +` + +func (q *Queries) GetChar3(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getChar3) + var char string + err := row.Scan(&char) + return char, err +} + +const getCoalesce = `-- name: GetCoalesce :one +SELECT coalesce(NULL, 1, 'test') +` + +func (q *Queries) GetCoalesce(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, getCoalesce) + var coalesce interface{} + err := row.Scan(&coalesce) + return coalesce, err +} + +const getFormat = `-- name: GetFormat :one +SELECT format('Hello %s', 'world') +` + +func (q *Queries) GetFormat(ctx context.Context) (sql.NullString, error) { + row := q.db.QueryRowContext(ctx, getFormat) + var format sql.NullString + err := row.Scan(&format) + return format, err +} + +const getGlob = `-- name: GetGlob :one +SELECT glob('a*c', 'abc') +` + +func (q *Queries) GetGlob(ctx context.Context) (int64, error) { + row := q.db.QueryRowContext(ctx, getGlob) + var glob int64 + err := row.Scan(&glob) + return glob, err +} + +const getHex = `-- name: GetHex :one +SELECT hex(123456) +` + +func (q *Queries) GetHex(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getHex) + var hex string + err := row.Scan(&hex) + return hex, err +} + +const getIfnull = `-- name: GetIfnull :one +SELECT ifnull(1, 2) +` + +func (q *Queries) GetIfnull(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, getIfnull) + var ifnull interface{} + err := row.Scan(&ifnull) + return ifnull, err +} + +const getIif = `-- name: GetIif :one +SELECT iif(1, 2, 3) +` + +func (q *Queries) GetIif(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, getIif) + var iif interface{} + err := row.Scan(&iif) + return iif, err +} + +const getInstr = `-- name: GetInstr :one +SELECT instr('hello', 'l') +` + +func (q *Queries) GetInstr(ctx context.Context) (sql.NullInt64, error) { + row := q.db.QueryRowContext(ctx, getInstr) + var instr sql.NullInt64 + err := row.Scan(&instr) + return instr, err +} + +const getLastInsertRowID = `-- name: GetLastInsertRowID :one +SELECT last_insert_rowid() +` + +func (q *Queries) GetLastInsertRowID(ctx context.Context) (int64, error) { + row := q.db.QueryRowContext(ctx, getLastInsertRowID) + var last_insert_rowid int64 + err := row.Scan(&last_insert_rowid) + return last_insert_rowid, err +} + +const getLength = `-- name: GetLength :one +SELECT length('12345') +` + +func (q *Queries) GetLength(ctx context.Context) (sql.NullInt64, error) { + row := q.db.QueryRowContext(ctx, getLength) + var length sql.NullInt64 + err := row.Scan(&length) + return length, err +} + +const getLike2 = `-- name: GetLike2 :one +SELECT like('%bc%', 'abcd') +` + +func (q *Queries) GetLike2(ctx context.Context) (int64, error) { + row := q.db.QueryRowContext(ctx, getLike2) + var like int64 + err := row.Scan(&like) + return like, err +} + +const getLike3 = `-- name: GetLike3 :one +SELECT like('$%1%', '%100', '$') +` + +func (q *Queries) GetLike3(ctx context.Context) (int64, error) { + row := q.db.QueryRowContext(ctx, getLike3) + var like int64 + err := row.Scan(&like) + return like, err +} + +const getLikelihood = `-- name: GetLikelihood :one +SELECT likelihood('12345', 0.5) +` + +func (q *Queries) GetLikelihood(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, getLikelihood) + var likelihood interface{} + err := row.Scan(&likelihood) + return likelihood, err +} + +const getLikely = `-- name: GetLikely :one +SELECT likely('12345') +` + +func (q *Queries) GetLikely(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, getLikely) + var likely interface{} + err := row.Scan(&likely) + return likely, err +} + +const getLower = `-- name: GetLower :one +SELECT lower('ABCDE') +` + +func (q *Queries) GetLower(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getLower) + var lower string + err := row.Scan(&lower) + return lower, err +} + +const getLtrim = `-- name: GetLtrim :one +SELECT ltrim(' ABCDE') +` + +func (q *Queries) GetLtrim(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getLtrim) + var ltrim string + err := row.Scan(<rim) + return ltrim, err +} + +const getLtrim2 = `-- name: GetLtrim2 :one +SELECT ltrim(':ABCDE', ':') +` + +func (q *Queries) GetLtrim2(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getLtrim2) + var ltrim string + err := row.Scan(<rim) + return ltrim, err +} + +const getMax3 = `-- name: GetMax3 :one +SELECT max(1, 3, 2) +` + +func (q *Queries) GetMax3(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, getMax3) + var max interface{} + err := row.Scan(&max) + return max, err +} + +const getMin3 = `-- name: GetMin3 :one +SELECT min(1, 3, 2) +` + +func (q *Queries) GetMin3(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, getMin3) + var min interface{} + err := row.Scan(&min) + return min, err +} + +const getNullif = `-- name: GetNullif :one +SELECT nullif(1, 2) +` + +func (q *Queries) GetNullif(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, getNullif) + var nullif interface{} + err := row.Scan(&nullif) + return nullif, err +} + +const getPrintf = `-- name: GetPrintf :one +SELECT printf('Hello %s', 'world') +` + +func (q *Queries) GetPrintf(ctx context.Context) (sql.NullString, error) { + row := q.db.QueryRowContext(ctx, getPrintf) + var printf sql.NullString + err := row.Scan(&printf) + return printf, err +} + +const getQuote = `-- name: GetQuote :one +SELECT quote(1) +` + +func (q *Queries) GetQuote(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getQuote) + var quote string + err := row.Scan("e) + return quote, err +} + +const getRandom = `-- name: GetRandom :one +SELECT random() +` + +func (q *Queries) GetRandom(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, getRandom) + var random interface{} + err := row.Scan(&random) + return random, err +} + +const getRandomBlob = `-- name: GetRandomBlob :one +SELECT randomblob(16) +` + +func (q *Queries) GetRandomBlob(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, getRandomBlob) + var randomblob interface{} + err := row.Scan(&randomblob) + return randomblob, err +} + +const getReplace = `-- name: GetReplace :one +SELECT replace('abc', 'bc', 'df') +` + +func (q *Queries) GetReplace(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getReplace) + var replace string + err := row.Scan(&replace) + return replace, err +} + +const getRound = `-- name: GetRound :one +SELECT round(1.1) +` + +func (q *Queries) GetRound(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getRound) + var round float64 + err := row.Scan(&round) + return round, err +} + +const getRound2 = `-- name: GetRound2 :one +SELECT round(1.1, 2) +` + +func (q *Queries) GetRound2(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, getRound2) + var round float64 + err := row.Scan(&round) + return round, err +} + +const getRtrim = `-- name: GetRtrim :one +SELECT rtrim('ABCDE ') +` + +func (q *Queries) GetRtrim(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getRtrim) + var rtrim string + err := row.Scan(&rtrim) + return rtrim, err +} + +const getRtrim2 = `-- name: GetRtrim2 :one +SELECT rtrim('ABCDE:', ':') +` + +func (q *Queries) GetRtrim2(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getRtrim2) + var rtrim string + err := row.Scan(&rtrim) + return rtrim, err +} + +const getSQLiteCompileOptionGet = `-- name: GetSQLiteCompileOptionGet :one +SELECT sqlite_compileoption_get(1) +` + +func (q *Queries) GetSQLiteCompileOptionGet(ctx context.Context) (sql.NullString, error) { + row := q.db.QueryRowContext(ctx, getSQLiteCompileOptionGet) + var sqlite_compileoption_get sql.NullString + err := row.Scan(&sqlite_compileoption_get) + return sqlite_compileoption_get, err +} + +const getSQLiteCompileOptionUsed = `-- name: GetSQLiteCompileOptionUsed :one +SELECT sqlite_compileoption_used(1) +` + +func (q *Queries) GetSQLiteCompileOptionUsed(ctx context.Context) (int64, error) { + row := q.db.QueryRowContext(ctx, getSQLiteCompileOptionUsed) + var sqlite_compileoption_used int64 + err := row.Scan(&sqlite_compileoption_used) + return sqlite_compileoption_used, err +} + +const getSQLiteOffset = `-- name: GetSQLiteOffset :one +SELECT sqlite_offset(1) +` + +func (q *Queries) GetSQLiteOffset(ctx context.Context) (sql.NullInt64, error) { + row := q.db.QueryRowContext(ctx, getSQLiteOffset) + var sqlite_offset sql.NullInt64 + err := row.Scan(&sqlite_offset) + return sqlite_offset, err +} + +const getSQLiteSourceID = `-- name: GetSQLiteSourceID :one +SELECT sqlite_source_id() +` + +func (q *Queries) GetSQLiteSourceID(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getSQLiteSourceID) + var sqlite_source_id string + err := row.Scan(&sqlite_source_id) + return sqlite_source_id, err +} + +const getSQLiteVersion = `-- name: GetSQLiteVersion :one +SELECT sqlite_version() +` + +func (q *Queries) GetSQLiteVersion(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getSQLiteVersion) + var sqlite_version string + err := row.Scan(&sqlite_version) + return sqlite_version, err +} + +const getSign = `-- name: GetSign :one +SELECT sign(1) +` + +func (q *Queries) GetSign(ctx context.Context) (sql.NullInt64, error) { + row := q.db.QueryRowContext(ctx, getSign) + var sign sql.NullInt64 + err := row.Scan(&sign) + return sign, err +} + +const getSoundex = `-- name: GetSoundex :one +SELECT soundex('abc') +` + +func (q *Queries) GetSoundex(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getSoundex) + var soundex string + err := row.Scan(&soundex) + return soundex, err +} + +const getSubstr2 = `-- name: GetSubstr2 :one +SELECT substr('abcdef', 2) +` + +func (q *Queries) GetSubstr2(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getSubstr2) + var substr string + err := row.Scan(&substr) + return substr, err +} + +const getSubstr3 = `-- name: GetSubstr3 :one +SELECT substr('abcdef', 1, 2) +` + +func (q *Queries) GetSubstr3(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getSubstr3) + var substr string + err := row.Scan(&substr) + return substr, err +} + +const getSubstring2 = `-- name: GetSubstring2 :one +SELECT substring('abcdef', 1) +` + +func (q *Queries) GetSubstring2(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getSubstring2) + var substring string + err := row.Scan(&substring) + return substring, err +} + +const getSusbstring3 = `-- name: GetSusbstring3 :one +SELECT substring('abcdef', 1, 2) +` + +func (q *Queries) GetSusbstring3(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getSusbstring3) + var substring string + err := row.Scan(&substring) + return substring, err +} + +const getTotalChanges = `-- name: GetTotalChanges :one +SELECT total_changes() +` + +func (q *Queries) GetTotalChanges(ctx context.Context) (int64, error) { + row := q.db.QueryRowContext(ctx, getTotalChanges) + var total_changes int64 + err := row.Scan(&total_changes) + return total_changes, err +} + +const getTrim = `-- name: GetTrim :one +SELECT trim(' ABCDE ') +` + +func (q *Queries) GetTrim(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getTrim) + var trim string + err := row.Scan(&trim) + return trim, err +} + +const getTrim2 = `-- name: GetTrim2 :one +SELECT trim(':ABCDE:', ':') +` + +func (q *Queries) GetTrim2(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getTrim2) + var trim string + err := row.Scan(&trim) + return trim, err +} + +const getTypeof = `-- name: GetTypeof :one +SELECT typeof('ABCDE') +` + +func (q *Queries) GetTypeof(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getTypeof) + var typeof string + err := row.Scan(&typeof) + return typeof, err +} + +const getUnicode = `-- name: GetUnicode :one +SELECT unicode('A') +` + +func (q *Queries) GetUnicode(ctx context.Context) (int64, error) { + row := q.db.QueryRowContext(ctx, getUnicode) + var unicode int64 + err := row.Scan(&unicode) + return unicode, err +} + +const getUnlikely = `-- name: GetUnlikely :one +SELECT unlikely('12345') +` + +func (q *Queries) GetUnlikely(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, getUnlikely) + var unlikely interface{} + err := row.Scan(&unlikely) + return unlikely, err +} + +const getUpper = `-- name: GetUpper :one +SELECT upper('abcde') +` + +func (q *Queries) GetUpper(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getUpper) + var upper string + err := row.Scan(&upper) + return upper, err +} + +const getZeroblob = `-- name: GetZeroblob :one +SELECT zeroblob(16) +` + +func (q *Queries) GetZeroblob(ctx context.Context) ([]uint8, error) { + row := q.db.QueryRowContext(ctx, getZeroblob) + var zeroblob []uint8 + err := row.Scan(pq.Array(&zeroblob)) + return zeroblob, err +} diff --git a/internal/endtoend/testdata/builtins/sqlite/queries/aggfunc.sql b/internal/endtoend/testdata/builtins/sqlite/queries/aggfunc.sql new file mode 100644 index 0000000000..5af32cdbcc --- /dev/null +++ b/internal/endtoend/testdata/builtins/sqlite/queries/aggfunc.sql @@ -0,0 +1,41 @@ +-- name: GetAvg :one +SELECT avg(int_val) FROM test; + +-- name: GetCount :one +SELECT count(*) FROM test; + +-- name: GetCountId :one +SELECT count(id) FROM test; + +-- name: GetGroupConcatInt :one +SELECT group_concat(int_val) FROM test; + +-- name: GetGroupConcatInt2 :one +SELECT group_concat(1, ':') FROM test; + +-- name: GetGroupConcatText :one +SELECT group_concat(text_val) FROM test; + +-- name: GetGroupConcatText2 :one +SELECT group_concat(text_val, ':') FROM test; + +-- name: GetMaxInt :one +SELECT max(int_val) FROM test; + +-- name: GetMaxText :one +SELECT max(text_val) FROM test; + +-- name: GetMinInt :one +SELECT min(int_val) FROM test; + +-- name: GetMinText :one +SELECT min(text_val) FROM test; + +-- name: GetSumInt :one +SELECT sum(int_val) FROM test; + +-- name: GetSumText :one +SELECT sum(text_val) FROM test; + +-- name: GetTotalInt :one +SELECT total(int_val) FROM test; diff --git a/internal/endtoend/testdata/builtins/sqlite/queries/mathfunc.sql b/internal/endtoend/testdata/builtins/sqlite/queries/mathfunc.sql new file mode 100644 index 0000000000..d62c2b6521 --- /dev/null +++ b/internal/endtoend/testdata/builtins/sqlite/queries/mathfunc.sql @@ -0,0 +1,86 @@ +-- name: GetAcos :one +select acos(1.0); + +-- name: GetAcosh :one +select acosh(1.0); + +-- name: GetAsin :one +select asin(1.0); + +-- name: GetAsinh :one +select asinh(1.0); + +-- name: GetAtan :one +select atan(1.0); + +-- name: GetAtan2 :one +select atan2(1.0, 0.5); + +-- name: GetAtanh :one +select atanh(1.0); + +-- name: GetCeil :one +select ceil(1.0); + +-- name: GetCeilin :one +select ceiling(1.0); + +-- name: GetCos :one +select cos(1.0); + +-- name: GetCosh :one +select cosh(1.0); + +-- name: GetDegrees :one +select degrees(1.0); + +-- name: GetExp :one +select exp(1.0); + +-- name: GetFloor :one +select floor(1.0); + +-- name: GetLn :one +select ln(1.0); + +-- name: GetLog :one +select log(1.0); + +-- name: GetLog10 :one +select log10(1.0); + +-- name: GetLogBase :one +select log(1.0, 2.0); + +-- name: GetLog2 :one +select log2(1.0); + +-- name: GetMod :one +select mod(1, 2); + +-- name: GetPi :one +select pi(); + +-- name: GetPow :one +select pow(1, 2); + +-- name: GetPower :one +select power(1, 2); + +-- name: GetRadians :one +select radians(1); + +-- name: GetSin :one +select sin(1.0); + +-- name: GetSinh :one +select sinh(1.0); + +-- name: GetSqrt :one +select sqrt(1.0); + +-- name: GetTan :one +select tan(1.0); + +-- name: GetTrunc :one +select trunc(1.0); diff --git a/internal/endtoend/testdata/builtins/sqlite/queries/scalarfunc.sql b/internal/endtoend/testdata/builtins/sqlite/queries/scalarfunc.sql new file mode 100644 index 0000000000..728a6be1a5 --- /dev/null +++ b/internal/endtoend/testdata/builtins/sqlite/queries/scalarfunc.sql @@ -0,0 +1,152 @@ +-- name: GetAbs :one +SELECT abs(int_val) FROM test; + +-- name: GetChanges :one +SELECT changes(); + +-- name: GetChar1 :one +SELECT char(65); + +-- name: GetChar3 :one +SELECT char(65, 66, 67); + +-- name: GetCoalesce :one +SELECT coalesce(NULL, 1, 'test'); + +-- name: GetFormat :one +SELECT format('Hello %s', 'world'); + +-- name: GetGlob :one +SELECT glob('a*c', 'abc'); + +-- name: GetHex :one +SELECT hex(123456); + +-- name: GetIfnull :one +SELECT ifnull(1, 2); + +-- name: GetIif :one +SELECT iif(1, 2, 3); + +-- name: GetLastInsertRowID :one +SELECT last_insert_rowid(); + +-- name: GetInstr :one +SELECT instr('hello', 'l'); + +-- name: GetLength :one +SELECT length('12345'); + +-- name: GetLike2 :one +SELECT like('%bc%', 'abcd'); + +-- name: GetLike3 :one +SELECT like('$%1%', '%100', '$'); + +-- name: GetLikelihood :one +SELECT likelihood('12345', 0.5); + +-- name: GetLikely :one +SELECT likely('12345'); + +-- name: GetLower :one +SELECT lower('ABCDE'); + +-- name: GetLtrim :one +SELECT ltrim(' ABCDE'); + +-- name: GetLtrim2 :one +SELECT ltrim(':ABCDE', ':'); + +-- name: GetMax3 :one +SELECT max(1, 3, 2); + +-- name: GetMin3 :one +SELECT min(1, 3, 2); + +-- name: GetNullif :one +SELECT nullif(1, 2); + +-- name: GetPrintf :one +SELECT printf('Hello %s', 'world'); + +-- name: GetQuote :one +SELECT quote(1); + +-- name: GetRandom :one +SELECT random(); + +-- name: GetRandomBlob :one +SELECT randomblob(16); + +-- name: GetRound :one +SELECT round(1.1); + +-- name: GetRound2 :one +SELECT round(1.1, 2); + +-- name: GetReplace :one +SELECT replace('abc', 'bc', 'df'); + +-- name: GetRtrim :one +SELECT rtrim('ABCDE '); + +-- name: GetRtrim2 :one +SELECT rtrim('ABCDE:', ':'); + +-- name: GetSign :one +SELECT sign(1); + +-- name: GetSoundex :one +SELECT soundex('abc'); + +-- name: GetSQLiteCompileOptionGet :one +SELECT sqlite_compileoption_get(1); + +-- name: GetSQLiteCompileOptionUsed :one +SELECT sqlite_compileoption_used(1); + +-- name: GetSQLiteOffset :one +SELECT sqlite_offset(1); + +-- name: GetSQLiteSourceID :one +SELECT sqlite_source_id(); + +-- name: GetSQLiteVersion :one +SELECT sqlite_version(); + +-- name: GetSubstr3 :one +SELECT substr('abcdef', 1, 2); + +-- name: GetSubstr2 :one +SELECT substr('abcdef', 2); + +-- name: GetSusbstring3 :one +SELECT substring('abcdef', 1, 2); + +-- name: GetSubstring2 :one +SELECT substring('abcdef', 1); + +-- name: GetTotalChanges :one +SELECT total_changes(); + +-- name: GetTrim :one +SELECT trim(' ABCDE '); + +-- name: GetTrim2 :one +SELECT trim(':ABCDE:', ':'); + +-- name: GetTypeof :one +SELECT typeof('ABCDE'); + +-- name: GetUnicode :one +SELECT unicode('A'); + +-- name: GetUnlikely :one +SELECT unlikely('12345'); + +-- name: GetUpper :one +SELECT upper('abcde'); + +-- name: GetZeroblob :one +SELECT zeroblob(16); diff --git a/internal/endtoend/testdata/builtins/sqlite/schema.sql b/internal/endtoend/testdata/builtins/sqlite/schema.sql new file mode 100644 index 0000000000..1c3d00e17b --- /dev/null +++ b/internal/endtoend/testdata/builtins/sqlite/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE test ( + id integer NOT NULL PRIMARY KEY AUTOINCREMENT, + int_val integer NOT NULL, + text_val text NOT NULL +); + \ No newline at end of file diff --git a/internal/endtoend/testdata/builtins/sqlite/sqlc.json b/internal/endtoend/testdata/builtins/sqlite/sqlc.json new file mode 100644 index 0000000000..ca4644740d --- /dev/null +++ b/internal/endtoend/testdata/builtins/sqlite/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "queries/", + "engine": "sqlite" + } + ] +} \ No newline at end of file diff --git a/internal/endtoend/testdata/func_match_types/sqlite/go/query.sql.go b/internal/endtoend/testdata/func_match_types/sqlite/go/query.sql.go index 08c0c26ff0..ba644392ec 100644 --- a/internal/endtoend/testdata/func_match_types/sqlite/go/query.sql.go +++ b/internal/endtoend/testdata/func_match_types/sqlite/go/query.sql.go @@ -7,6 +7,7 @@ package querytest import ( "context" + "database/sql" ) const authorPages = `-- name: AuthorPages :many @@ -18,7 +19,7 @@ group by author type AuthorPagesRow struct { Author string NumBooks int64 - TotalPages float64 + TotalPages sql.NullFloat64 } func (q *Queries) AuthorPages(ctx context.Context) ([]AuthorPagesRow, error) { diff --git a/internal/engine/sqlite/stdlib.go b/internal/engine/sqlite/stdlib.go index 91355d96b1..82dadf06c5 100644 --- a/internal/engine/sqlite/stdlib.go +++ b/internal/engine/sqlite/stdlib.go @@ -5,7 +5,7 @@ import ( "github.com/kyleconroy/sqlc/internal/sql/catalog" ) -// TODO: fill out sqlite functions from: +// sqlite functions from: // https://www.sqlite.org/lang_aggfunc.html // https://www.sqlite.org/lang_mathfunc.html // https://www.sqlite.org/lang_corefunc.html @@ -13,10 +13,21 @@ import ( func defaultSchema(name string) *catalog.Schema { s := &catalog.Schema{Name: name} s.Funcs = []*catalog.Function{ + // Aggregation Functions + { + Name: "AVG", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + ReturnTypeNullable: true, + }, { Name: "COUNT", Args: []*catalog.Argument{}, - ReturnType: &ast.TypeName{Name: "bigint"}, + ReturnType: &ast.TypeName{Name: "integer"}, }, { Name: "COUNT", @@ -25,34 +36,893 @@ func defaultSchema(name string) *catalog.Schema { Type: &ast.TypeName{Name: "any"}, }, }, - ReturnType: &ast.TypeName{Name: "bigint"}, + ReturnType: &ast.TypeName{Name: "integer"}, + }, + { + Name: "GROUP_CONCAT", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "GROUP_CONCAT", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "text"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "MAX", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "MIN", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, }, { Name: "SUM", Args: []*catalog.Argument{ { - Type: &ast.TypeName{Name: "real"}, + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + ReturnTypeNullable: true, + }, + { + Name: "TOTAL", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, }, }, ReturnType: &ast.TypeName{Name: "real"}, }, + + // Math Functions { - Name: "SUM", + Name: "ACOS", Args: []*catalog.Argument{ { - Type: &ast.TypeName{Name: "integer"}, + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "ACOSH", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "ASIN", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "ASINH", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "ATAN", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "ATAN2", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "ATANH", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "CEIL", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, }, }, ReturnType: &ast.TypeName{Name: "integer"}, }, { - Name: "SUM", + Name: "CEILING", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "integer"}, + }, + { + Name: "COS", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "COSH", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "DEGREES", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "EXP", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "FLOOR", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "integer"}, + }, + { + Name: "LN", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "LOG", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "LOG10", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "LOG", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "LOG2", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "MOD", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "PI", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "POW", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "POWER", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "RADIANS", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "SIN", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "SINH", Args: []*catalog.Argument{ { Type: &ast.TypeName{Name: "any"}, }, }, - ReturnType: &ast.TypeName{Name: "bigint"}, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "SQRT", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "TAN", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "TANH", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "TRUNC", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "integer"}, + }, + + // Scalar functions + { + Name: "ABS", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "CHANGES", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "integer"}, + }, + { + Name: "CHAR", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "int"}, + }, + { + Type: &ast.TypeName{Name: "int"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "COALESCE", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "FORMAT", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "text"}, + }, + { + Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + ReturnTypeNullable: true, + }, + { + Name: "GLOB", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "text"}, + }, + { + Type: &ast.TypeName{Name: "text"}, + }, + }, + ReturnType: &ast.TypeName{Name: "integer"}, + }, + { + Name: "HEX", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "IFNULL", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "IIF", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "INSTR", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "text"}, + }, + { + Type: &ast.TypeName{Name: "text"}, + }, + }, + ReturnType: &ast.TypeName{Name: "integer"}, + ReturnTypeNullable: true, + }, + { + Name: "LAST_INSERT_ROWID", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "integer"}, + }, + { + Name: "LENGTH", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "integer"}, + ReturnTypeNullable: true, + }, + { + Name: "LIKE", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "text"}, + }, + { + Type: &ast.TypeName{Name: "text"}, + }, + }, + ReturnType: &ast.TypeName{Name: "integer"}, + }, + { + Name: "LIKE", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "text"}, + }, + { + Type: &ast.TypeName{Name: "text"}, + }, + { + Type: &ast.TypeName{Name: "text"}, + }, + }, + ReturnType: &ast.TypeName{Name: "integer"}, + }, + { + Name: "LIKELIHOOD", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "real"}, + }, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "LIKELY", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "LOWER", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "text"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "LTRIM", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "text"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "LTRIM", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "text"}, + }, + { + Type: &ast.TypeName{Name: "text"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "MAX", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "MIN", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "NULLIF", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "PRINTF", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "text"}, + }, + { + Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + ReturnTypeNullable: true, + }, + { + Name: "QUOTE", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "RAMDOM", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "integer"}, + }, + { + Name: "RAMDOMBLOB", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "integer"}, + }, + }, + ReturnType: &ast.TypeName{Name: "blob"}, + }, + { + Name: "REPLACE", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "text"}, + }, + { + Type: &ast.TypeName{Name: "text"}, + }, + { + Type: &ast.TypeName{Name: "text"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "ROUND", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "real"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "ROUND", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "real"}, + }, + { + Type: &ast.TypeName{Name: "real"}, + }, + }, + ReturnType: &ast.TypeName{Name: "real"}, + }, + { + Name: "RTRIM", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "text"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "RTRIM", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "text"}, + }, + { + Type: &ast.TypeName{Name: "text"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "SIGN", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "integer"}, + ReturnTypeNullable: true, + }, + { + Name: "SOUNDEX", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "text"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "SQLITE_COMPILEOPTION_GET", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "integer"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + ReturnTypeNullable: true, + }, + { + Name: "SQLITE_COMPILEOPTION_USED", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "text"}, + }, + }, + ReturnType: &ast.TypeName{Name: "integer"}, + }, + { + Name: "SQLITE_OFFSET", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "integer"}, + ReturnTypeNullable: true, + }, + { + Name: "SQLITE_SOURCE_ID", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "SQLITE_VERSION", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "SUBSTR", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "integer"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "SUBSTR", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "integer"}, + }, + { + Type: &ast.TypeName{Name: "integer"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "SUBSTRING", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "integer"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "SUBSTRING", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + { + Type: &ast.TypeName{Name: "integer"}, + }, + { + Type: &ast.TypeName{Name: "integer"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "TOTAL_CHANGES", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "integer"}, + }, + { + Name: "TRIM", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "text"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "TRIM", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "text"}, + }, + { + Type: &ast.TypeName{Name: "text"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "TYPEOF", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "UNICODE", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "integer"}, + }, + { + Name: "UNLIKELY", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + }, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "UPPER", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "text"}, + }, + }, + ReturnType: &ast.TypeName{Name: "text"}, + }, + { + Name: "ZEROBLOB", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "integer"}, + }, + }, + ReturnType: &ast.TypeName{Name: "blob"}, }, } return s