// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: query.sql package catalogdb import ( "context" "database/sql" "strings" ) const classAttributes = `-- name: ClassAttributes :many SELECT oid, name, type_oid, not_null, hidden FROM sql_attribute WHERE class_oid = ? ORDER BY num ` type ClassAttributesRow struct { Oid int64 Name string TypeOid int64 NotNull int64 Hidden int64 } func (q *Queries) ClassAttributes(ctx context.Context, classOid int64) ([]ClassAttributesRow, error) { rows, err := q.db.QueryContext(ctx, classAttributes, classOid) if err != nil { return nil, err } defer rows.Close() var items []ClassAttributesRow for rows.Next() { var i ClassAttributesRow if err := rows.Scan( &i.Oid, &i.Name, &i.TypeOid, &i.NotNull, &i.Hidden, ); 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 classOID = `-- name: ClassOID :one SELECT oid FROM sql_class WHERE namespace_oid = ? AND name = ? ` type ClassOIDParams struct { NamespaceOid int64 Name string } func (q *Queries) ClassOID(ctx context.Context, arg ClassOIDParams) (int64, error) { row := q.db.QueryRowContext(ctx, classOID, arg.NamespaceOid, arg.Name) var oid int64 err := row.Scan(&oid) return oid, err } const classOIDByName = `-- name: ClassOIDByName :one SELECT oid FROM sql_class WHERE name = ? LIMIT 1 ` func (q *Queries) ClassOIDByName(ctx context.Context, name string) (int64, error) { row := q.db.QueryRowContext(ctx, classOIDByName, name) var oid int64 err := row.Scan(&oid) return oid, err } const createAttribute = `-- name: CreateAttribute :exec INSERT INTO sql_attribute ( class_oid, name, type_oid, not_null, has_default, num, decl_type, auto_increment, is_primary_key, is_unique, hidden ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ` type CreateAttributeParams struct { ClassOid int64 Name string TypeOid int64 NotNull int64 HasDefault int64 Num int64 DeclType string AutoIncrement int64 IsPrimaryKey int64 IsUnique int64 Hidden int64 } // ============================= sql_attribute =========================== func (q *Queries) CreateAttribute(ctx context.Context, arg CreateAttributeParams) error { _, err := q.db.ExecContext(ctx, createAttribute, arg.ClassOid, arg.Name, arg.TypeOid, arg.NotNull, arg.HasDefault, arg.Num, arg.DeclType, arg.AutoIncrement, arg.IsPrimaryKey, arg.IsUnique, arg.Hidden, ) return err } const createCast = `-- name: CreateCast :exec INSERT INTO sql_cast (source_type_oid, target_type_oid, proc_oid, context, dialect_oid) VALUES (?, ?, ?, ?, ?) ` type CreateCastParams struct { SourceTypeOid int64 TargetTypeOid int64 ProcOid sql.NullInt64 Context string DialectOid sql.NullInt64 } // =============================== sql_cast ============================== func (q *Queries) CreateCast(ctx context.Context, arg CreateCastParams) error { _, err := q.db.ExecContext(ctx, createCast, arg.SourceTypeOid, arg.TargetTypeOid, arg.ProcOid, arg.Context, arg.DialectOid, ) return err } const createClass = `-- name: CreateClass :execlastid INSERT INTO sql_class (namespace_oid, name, kind) VALUES (?, ?, ?) ` type CreateClassParams struct { NamespaceOid int64 Name string Kind string } // =============================== sql_class ============================= func (q *Queries) CreateClass(ctx context.Context, arg CreateClassParams) (int64, error) { result, err := q.db.ExecContext(ctx, createClass, arg.NamespaceOid, arg.Name, arg.Kind) if err != nil { return 0, err } return result.LastInsertId() } const createConstraint = `-- name: CreateConstraint :exec INSERT INTO sql_constraint (class_oid, name, kind, columns) VALUES (?, ?, ?, ?) ` type CreateConstraintParams struct { ClassOid int64 Name string Kind string Columns string } // ============================ sql_constraint =========================== func (q *Queries) CreateConstraint(ctx context.Context, arg CreateConstraintParams) error { _, err := q.db.ExecContext(ctx, createConstraint, arg.ClassOid, arg.Name, arg.Kind, arg.Columns, ) return err } const createDialect = `-- name: CreateDialect :execlastid INSERT INTO sql_dialect (name) VALUES (?) ` // ============================== sql_dialect ============================ func (q *Queries) CreateDialect(ctx context.Context, name string) (int64, error) { result, err := q.db.ExecContext(ctx, createDialect, name) if err != nil { return 0, err } return result.LastInsertId() } const createNamespace = `-- name: CreateNamespace :execlastid INSERT INTO sql_namespace (name) VALUES (?) ` // Queries against sqlc's own sql_* catalog tables, compiled by sqlc's // SQLite engine. Regenerate with `go generate ./internal/core/...`. // ============================ sql_namespace ============================ func (q *Queries) CreateNamespace(ctx context.Context, name string) (int64, error) { result, err := q.db.ExecContext(ctx, createNamespace, name) if err != nil { return 0, err } return result.LastInsertId() } const createOperator = `-- name: CreateOperator :execlastid INSERT INTO sql_operator (namespace_oid, dialect_oid, name, left_type_oid, right_type_oid, result_type_oid, proc_oid) VALUES (?, ?, ?, ?, ?, ?, ?) ` type CreateOperatorParams struct { NamespaceOid sql.NullInt64 DialectOid sql.NullInt64 Name string LeftTypeOid sql.NullInt64 RightTypeOid sql.NullInt64 ResultTypeOid int64 ProcOid sql.NullInt64 } // ============================= sql_operator ============================ func (q *Queries) CreateOperator(ctx context.Context, arg CreateOperatorParams) (int64, error) { result, err := q.db.ExecContext(ctx, createOperator, arg.NamespaceOid, arg.DialectOid, arg.Name, arg.LeftTypeOid, arg.RightTypeOid, arg.ResultTypeOid, arg.ProcOid, ) if err != nil { return 0, err } return result.LastInsertId() } const createProc = `-- name: CreateProc :execlastid INSERT INTO sql_proc (namespace_oid, dialect_oid, name, kind, return_type_oid, return_set, return_nullable, return_template, strict, variadic_kind) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ` type CreateProcParams struct { NamespaceOid sql.NullInt64 DialectOid sql.NullInt64 Name string Kind string ReturnTypeOid int64 ReturnSet int64 ReturnNullable int64 ReturnTemplate string Strict int64 VariadicKind string } // =============================== sql_proc ============================== func (q *Queries) CreateProc(ctx context.Context, arg CreateProcParams) (int64, error) { result, err := q.db.ExecContext(ctx, createProc, arg.NamespaceOid, arg.DialectOid, arg.Name, arg.Kind, arg.ReturnTypeOid, arg.ReturnSet, arg.ReturnNullable, arg.ReturnTemplate, arg.Strict, arg.VariadicKind, ) if err != nil { return 0, err } return result.LastInsertId() } const createProcArg = `-- name: CreateProcArg :exec INSERT INTO sql_proc_arg (proc_oid, ord, name, type_oid, mode, has_default) VALUES (?, ?, ?, ?, ?, ?) ` type CreateProcArgParams struct { ProcOid int64 Ord int64 Name string TypeOid int64 Mode string HasDefault int64 } func (q *Queries) CreateProcArg(ctx context.Context, arg CreateProcArgParams) error { _, err := q.db.ExecContext(ctx, createProcArg, arg.ProcOid, arg.Ord, arg.Name, arg.TypeOid, arg.Mode, arg.HasDefault, ) return err } const createType = `-- name: CreateType :execlastid INSERT INTO sql_type (name, expr, typtype, category, preferred, namespace_oid, dialect_oid, family_oid, element_oid, base_oid, canonical_oid, not_null) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ` type CreateTypeParams struct { Name string Expr string Typtype string Category sql.NullString Preferred int64 NamespaceOid int64 DialectOid sql.NullInt64 FamilyOid sql.NullInt64 ElementOid sql.NullInt64 BaseOid sql.NullInt64 CanonicalOid sql.NullInt64 NotNull int64 } // =============================== sql_type ============================== func (q *Queries) CreateType(ctx context.Context, arg CreateTypeParams) (int64, error) { result, err := q.db.ExecContext(ctx, createType, arg.Name, arg.Expr, arg.Typtype, arg.Category, arg.Preferred, arg.NamespaceOid, arg.DialectOid, arg.FamilyOid, arg.ElementOid, arg.BaseOid, arg.CanonicalOid, arg.NotNull, ) if err != nil { return 0, err } return result.LastInsertId() } const createTypeAffinity = `-- name: CreateTypeAffinity :exec INSERT INTO sql_type_affinity (dialect_oid, ord, words, type_oid) VALUES (?, ?, ?, ?) ` type CreateTypeAffinityParams struct { DialectOid int64 Ord int64 Words string TypeOid int64 } func (q *Queries) CreateTypeAffinity(ctx context.Context, arg CreateTypeAffinityParams) error { _, err := q.db.ExecContext(ctx, createTypeAffinity, arg.DialectOid, arg.Ord, arg.Words, arg.TypeOid, ) return err } const createTypeArg = `-- name: CreateTypeArg :exec INSERT INTO sql_type_arg (type_oid, ord, label, arg_type_oid, nullable, int_value, bool_value, string_value, ident) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ` type CreateTypeArgParams struct { TypeOid int64 Ord int64 Label string ArgTypeOid sql.NullInt64 Nullable int64 IntValue sql.NullInt64 BoolValue sql.NullInt64 StringValue sql.NullString Ident sql.NullString } func (q *Queries) CreateTypeArg(ctx context.Context, arg CreateTypeArgParams) error { _, err := q.db.ExecContext(ctx, createTypeArg, arg.TypeOid, arg.Ord, arg.Label, arg.ArgTypeOid, arg.Nullable, arg.IntValue, arg.BoolValue, arg.StringValue, arg.Ident, ) return err } const createTypeRewrite = `-- name: CreateTypeRewrite :exec INSERT INTO sql_type_rewrite (dialect_oid, ord, pattern, template, cond) VALUES (?, ?, ?, ?, ?) ` type CreateTypeRewriteParams struct { DialectOid int64 Ord int64 Pattern string Template string Cond string } func (q *Queries) CreateTypeRewrite(ctx context.Context, arg CreateTypeRewriteParams) error { _, err := q.db.ExecContext(ctx, createTypeRewrite, arg.DialectOid, arg.Ord, arg.Pattern, arg.Template, arg.Cond, ) return err } const deleteAttribute = `-- name: DeleteAttribute :exec DELETE FROM sql_attribute WHERE class_oid = ? AND name = ? ` type DeleteAttributeParams struct { ClassOid int64 Name string } func (q *Queries) DeleteAttribute(ctx context.Context, arg DeleteAttributeParams) error { _, err := q.db.ExecContext(ctx, deleteAttribute, arg.ClassOid, arg.Name) return err } const deleteAttributesByClass = `-- name: DeleteAttributesByClass :exec DELETE FROM sql_attribute WHERE class_oid = ? ` func (q *Queries) DeleteAttributesByClass(ctx context.Context, classOid int64) error { _, err := q.db.ExecContext(ctx, deleteAttributesByClass, classOid) return err } const deleteClass = `-- name: DeleteClass :exec DELETE FROM sql_class WHERE oid = ? ` func (q *Queries) DeleteClass(ctx context.Context, oid int64) error { _, err := q.db.ExecContext(ctx, deleteClass, oid) return err } const dialectFlag = `-- name: DialectFlag :one SELECT value FROM sql_dialect_flag WHERE dialect_oid = ? AND key = ? ` type DialectFlagParams struct { DialectOid int64 Key string } func (q *Queries) DialectFlag(ctx context.Context, arg DialectFlagParams) (string, error) { row := q.db.QueryRowContext(ctx, dialectFlag, arg.DialectOid, arg.Key) var value string err := row.Scan(&value) return value, err } const dialectOID = `-- name: DialectOID :one SELECT oid FROM sql_dialect WHERE name = ? ` func (q *Queries) DialectOID(ctx context.Context, name string) (int64, error) { row := q.db.QueryRowContext(ctx, dialectOID, name) var oid int64 err := row.Scan(&oid) return oid, err } const findCast = `-- name: FindCast :one SELECT source_type_oid, target_type_oid, proc_oid, context, dialect_oid FROM sql_cast WHERE source_type_oid = ? AND target_type_oid = ? ` type FindCastParams struct { SourceTypeOid int64 TargetTypeOid int64 } func (q *Queries) FindCast(ctx context.Context, arg FindCastParams) (SqlCast, error) { row := q.db.QueryRowContext(ctx, findCast, arg.SourceTypeOid, arg.TargetTypeOid) var i SqlCast err := row.Scan( &i.SourceTypeOid, &i.TargetTypeOid, &i.ProcOid, &i.Context, &i.DialectOid, ) return i, err } const findOperators = `-- name: FindOperators :many SELECT oid, name, left_type_oid, right_type_oid, result_type_oid, proc_oid FROM sql_operator WHERE name = ?1 AND (?2 = 0 OR left_type_oid = ?2) AND (?3 = 0 OR right_type_oid = ?3) ` type FindOperatorsParams struct { Name string LeftTypeOid any RightTypeOid any } type FindOperatorsRow struct { Oid int64 Name string LeftTypeOid sql.NullInt64 RightTypeOid sql.NullInt64 ResultTypeOid int64 ProcOid sql.NullInt64 } func (q *Queries) FindOperators(ctx context.Context, arg FindOperatorsParams) ([]FindOperatorsRow, error) { rows, err := q.db.QueryContext(ctx, findOperators, arg.Name, arg.LeftTypeOid, arg.RightTypeOid) if err != nil { return nil, err } defer rows.Close() var items []FindOperatorsRow for rows.Next() { var i FindOperatorsRow if err := rows.Scan( &i.Oid, &i.Name, &i.LeftTypeOid, &i.RightTypeOid, &i.ResultTypeOid, &i.ProcOid, ); 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 findProcsAnyNamespace = `-- name: FindProcsAnyNamespace :many SELECT oid, name, kind, return_type_oid, return_nullable, return_template FROM sql_proc WHERE name = ? ` type FindProcsAnyNamespaceRow struct { Oid int64 Name string Kind string ReturnTypeOid int64 ReturnNullable int64 ReturnTemplate string } func (q *Queries) FindProcsAnyNamespace(ctx context.Context, name string) ([]FindProcsAnyNamespaceRow, error) { rows, err := q.db.QueryContext(ctx, findProcsAnyNamespace, name) if err != nil { return nil, err } defer rows.Close() var items []FindProcsAnyNamespaceRow for rows.Next() { var i FindProcsAnyNamespaceRow if err := rows.Scan( &i.Oid, &i.Name, &i.Kind, &i.ReturnTypeOid, &i.ReturnNullable, &i.ReturnTemplate, ); 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 findProcsInNamespaces = `-- name: FindProcsInNamespaces :many SELECT oid, name, kind, return_type_oid, return_nullable, return_template FROM sql_proc WHERE name = ?1 AND namespace_oid IN (/*SLICE:namespace_oids*/?) ` type FindProcsInNamespacesParams struct { Name string NamespaceOids []sql.NullInt64 } type FindProcsInNamespacesRow struct { Oid int64 Name string Kind string ReturnTypeOid int64 ReturnNullable int64 ReturnTemplate string } func (q *Queries) FindProcsInNamespaces(ctx context.Context, arg FindProcsInNamespacesParams) ([]FindProcsInNamespacesRow, error) { query := findProcsInNamespaces var queryParams []any queryParams = append(queryParams, arg.Name) if len(arg.NamespaceOids) > 0 { for _, v := range arg.NamespaceOids { queryParams = append(queryParams, v) } query = strings.Replace(query, "/*SLICE:namespace_oids*/?", strings.Repeat(",?", len(arg.NamespaceOids))[1:], 1) } else { query = strings.Replace(query, "/*SLICE:namespace_oids*/?", "NULL", 1) } rows, err := q.db.QueryContext(ctx, query, queryParams...) if err != nil { return nil, err } defer rows.Close() var items []FindProcsInNamespacesRow for rows.Next() { var i FindProcsInNamespacesRow if err := rows.Scan( &i.Oid, &i.Name, &i.Kind, &i.ReturnTypeOid, &i.ReturnNullable, &i.ReturnTemplate, ); 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 listClassColumns = `-- name: ListClassColumns :many SELECT a.name AS column_name, a.type_oid, a.not_null FROM sql_attribute a JOIN sql_type t ON t.oid = a.type_oid WHERE a.class_oid = ? AND a.hidden = 0 ORDER BY a.num ` type ListClassColumnsRow struct { ColumnName string TypeOid int64 NotNull int64 } func (q *Queries) ListClassColumns(ctx context.Context, classOid int64) ([]ListClassColumnsRow, error) { rows, err := q.db.QueryContext(ctx, listClassColumns, classOid) if err != nil { return nil, err } defer rows.Close() var items []ListClassColumnsRow for rows.Next() { var i ListClassColumnsRow if err := rows.Scan(&i.ColumnName, &i.TypeOid, &i.NotNull); 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 listNamespaces = `-- name: ListNamespaces :many SELECT oid, name FROM sql_namespace ORDER BY oid ` func (q *Queries) ListNamespaces(ctx context.Context) ([]SqlNamespace, error) { rows, err := q.db.QueryContext(ctx, listNamespaces) if err != nil { return nil, err } defer rows.Close() var items []SqlNamespace for rows.Next() { var i SqlNamespace if err := rows.Scan(&i.Oid, &i.Name); 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 listTablesInNamespace = `-- name: ListTablesInNamespace :many SELECT oid, name FROM sql_class WHERE namespace_oid = ? AND kind = 'r' ORDER BY oid ` type ListTablesInNamespaceRow struct { Oid int64 Name string } func (q *Queries) ListTablesInNamespace(ctx context.Context, namespaceOid int64) ([]ListTablesInNamespaceRow, error) { rows, err := q.db.QueryContext(ctx, listTablesInNamespace, namespaceOid) if err != nil { return nil, err } defer rows.Close() var items []ListTablesInNamespaceRow for rows.Next() { var i ListTablesInNamespaceRow if err := rows.Scan(&i.Oid, &i.Name); 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 listTypeAffinities = `-- name: ListTypeAffinities :many SELECT words, type_oid FROM sql_type_affinity WHERE dialect_oid = ? ORDER BY ord ` type ListTypeAffinitiesRow struct { Words string TypeOid int64 } func (q *Queries) ListTypeAffinities(ctx context.Context, dialectOid int64) ([]ListTypeAffinitiesRow, error) { rows, err := q.db.QueryContext(ctx, listTypeAffinities, dialectOid) if err != nil { return nil, err } defer rows.Close() var items []ListTypeAffinitiesRow for rows.Next() { var i ListTypeAffinitiesRow if err := rows.Scan(&i.Words, &i.TypeOid); 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 listTypeRewrites = `-- name: ListTypeRewrites :many SELECT pattern, template, cond FROM sql_type_rewrite WHERE dialect_oid = ? ORDER BY ord ` type ListTypeRewritesRow struct { Pattern string Template string Cond string } func (q *Queries) ListTypeRewrites(ctx context.Context, dialectOid int64) ([]ListTypeRewritesRow, error) { rows, err := q.db.QueryContext(ctx, listTypeRewrites, dialectOid) if err != nil { return nil, err } defer rows.Close() var items []ListTypeRewritesRow for rows.Next() { var i ListTypeRewritesRow if err := rows.Scan(&i.Pattern, &i.Template, &i.Cond); 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 lookupAttribute = `-- name: LookupAttribute :one SELECT ns.name AS schema_name, cls.name AS table_name, a.name AS column_name, a.num, a.decl_type, a.auto_increment, a.is_primary_key, a.is_unique, a.not_null FROM sql_attribute a JOIN sql_class cls ON cls.oid = a.class_oid JOIN sql_namespace ns ON ns.oid = cls.namespace_oid WHERE a.oid = ? ` type LookupAttributeRow struct { SchemaName string TableName string ColumnName string Num int64 DeclType string AutoIncrement int64 IsPrimaryKey int64 IsUnique int64 NotNull int64 } func (q *Queries) LookupAttribute(ctx context.Context, oid int64) (LookupAttributeRow, error) { row := q.db.QueryRowContext(ctx, lookupAttribute, oid) var i LookupAttributeRow err := row.Scan( &i.SchemaName, &i.TableName, &i.ColumnName, &i.Num, &i.DeclType, &i.AutoIncrement, &i.IsPrimaryKey, &i.IsUnique, &i.NotNull, ) return i, err } const lookupType = `-- name: LookupType :one SELECT oid, namespace_oid, name, expr, category, typtype, preferred, family_oid, element_oid, base_oid, canonical_oid, not_null FROM sql_type WHERE oid = ? ` type LookupTypeRow struct { Oid int64 NamespaceOid int64 Name string Expr string Category sql.NullString Typtype string Preferred int64 FamilyOid sql.NullInt64 ElementOid sql.NullInt64 BaseOid sql.NullInt64 CanonicalOid sql.NullInt64 NotNull int64 } func (q *Queries) LookupType(ctx context.Context, oid int64) (LookupTypeRow, error) { row := q.db.QueryRowContext(ctx, lookupType, oid) var i LookupTypeRow err := row.Scan( &i.Oid, &i.NamespaceOid, &i.Name, &i.Expr, &i.Category, &i.Typtype, &i.Preferred, &i.FamilyOid, &i.ElementOid, &i.BaseOid, &i.CanonicalOid, &i.NotNull, ) return i, err } const maxAttributeNum = `-- name: MaxAttributeNum :one SELECT CAST(COALESCE(MAX(num), 0) AS INTEGER) AS num FROM sql_attribute WHERE class_oid = ? ` func (q *Queries) MaxAttributeNum(ctx context.Context, classOid int64) (int64, error) { row := q.db.QueryRowContext(ctx, maxAttributeNum, classOid) var num int64 err := row.Scan(&num) return num, err } const namespaceOID = `-- name: NamespaceOID :one SELECT oid FROM sql_namespace WHERE name = ? ` func (q *Queries) NamespaceOID(ctx context.Context, name string) (int64, error) { row := q.db.QueryRowContext(ctx, namespaceOID, name) var oid int64 err := row.Scan(&oid) return oid, err } const procArgTypes = `-- name: ProcArgTypes :many SELECT type_oid FROM sql_proc_arg WHERE proc_oid = ? AND mode IN ('i', 'b', 'v') ORDER BY ord ` func (q *Queries) ProcArgTypes(ctx context.Context, procOid int64) ([]int64, error) { rows, err := q.db.QueryContext(ctx, procArgTypes, procOid) if err != nil { return nil, err } defer rows.Close() var items []int64 for rows.Next() { var type_oid int64 if err := rows.Scan(&type_oid); err != nil { return nil, err } items = append(items, type_oid) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } const renameAttribute = `-- name: RenameAttribute :exec UPDATE sql_attribute SET name = ?1 WHERE class_oid = ?2 AND name = ?3 ` type RenameAttributeParams struct { NewName string ClassOid int64 Name string } func (q *Queries) RenameAttribute(ctx context.Context, arg RenameAttributeParams) error { _, err := q.db.ExecContext(ctx, renameAttribute, arg.NewName, arg.ClassOid, arg.Name) return err } const renameClass = `-- name: RenameClass :exec UPDATE sql_class SET name = ?1 WHERE oid = ?2 ` type RenameClassParams struct { NewName string Oid int64 } func (q *Queries) RenameClass(ctx context.Context, arg RenameClassParams) error { _, err := q.db.ExecContext(ctx, renameClass, arg.NewName, arg.Oid) return err } const resolveColumn = `-- name: ResolveColumn :one SELECT a.oid, a.class_oid, a.name, t.name AS type_name, a.type_oid, a.not_null, a.decl_type, a.auto_increment, a.is_primary_key, a.is_unique FROM sql_attribute a JOIN sql_class c ON c.oid = a.class_oid JOIN sql_type t ON t.oid = a.type_oid WHERE c.name = ?1 AND a.name = ?2 ` type ResolveColumnParams struct { TableName string ColumnName string } type ResolveColumnRow struct { Oid int64 ClassOid int64 Name string TypeName string TypeOid int64 NotNull int64 DeclType string AutoIncrement int64 IsPrimaryKey int64 IsUnique int64 } func (q *Queries) ResolveColumn(ctx context.Context, arg ResolveColumnParams) (ResolveColumnRow, error) { row := q.db.QueryRowContext(ctx, resolveColumn, arg.TableName, arg.ColumnName) var i ResolveColumnRow err := row.Scan( &i.Oid, &i.ClassOid, &i.Name, &i.TypeName, &i.TypeOid, &i.NotNull, &i.DeclType, &i.AutoIncrement, &i.IsPrimaryKey, &i.IsUnique, ) return i, err } const seededDialect = `-- name: SeededDialect :one SELECT oid, name FROM sql_dialect ORDER BY oid LIMIT 1 ` // The dialect a catalog was seeded with. A catalog is built for exactly one, // so a restored catalog finds it without being told its name. func (q *Queries) SeededDialect(ctx context.Context) (SqlDialect, error) { row := q.db.QueryRowContext(ctx, seededDialect) var i SqlDialect err := row.Scan(&i.Oid, &i.Name) return i, err } const setAttributeNotNull = `-- name: SetAttributeNotNull :exec UPDATE sql_attribute SET not_null = ?1 WHERE class_oid = ?2 AND name = ?3 ` type SetAttributeNotNullParams struct { NotNull int64 ClassOid int64 Name string } func (q *Queries) SetAttributeNotNull(ctx context.Context, arg SetAttributeNotNullParams) error { _, err := q.db.ExecContext(ctx, setAttributeNotNull, arg.NotNull, arg.ClassOid, arg.Name) return err } const setAttributePrimaryKey = `-- name: SetAttributePrimaryKey :exec UPDATE sql_attribute SET is_primary_key = 1, not_null = 1 WHERE class_oid = ? AND name = ? ` type SetAttributePrimaryKeyParams struct { ClassOid int64 Name string } func (q *Queries) SetAttributePrimaryKey(ctx context.Context, arg SetAttributePrimaryKeyParams) error { _, err := q.db.ExecContext(ctx, setAttributePrimaryKey, arg.ClassOid, arg.Name) return err } const setAttributeType = `-- name: SetAttributeType :exec UPDATE sql_attribute SET type_oid = ?1, decl_type = ?2 WHERE class_oid = ?3 AND name = ?4 ` type SetAttributeTypeParams struct { TypeOid int64 DeclType string ClassOid int64 Name string } func (q *Queries) SetAttributeType(ctx context.Context, arg SetAttributeTypeParams) error { _, err := q.db.ExecContext(ctx, setAttributeType, arg.TypeOid, arg.DeclType, arg.ClassOid, arg.Name, ) return err } const setAttributeUnique = `-- name: SetAttributeUnique :exec UPDATE sql_attribute SET is_unique = 1 WHERE class_oid = ? AND name = ? ` type SetAttributeUniqueParams struct { ClassOid int64 Name string } func (q *Queries) SetAttributeUnique(ctx context.Context, arg SetAttributeUniqueParams) error { _, err := q.db.ExecContext(ctx, setAttributeUnique, arg.ClassOid, arg.Name) return err } const setDialectFlag = `-- name: SetDialectFlag :exec INSERT INTO sql_dialect_flag (dialect_oid, key, value) VALUES (?, ?, ?) ON CONFLICT(dialect_oid, key) DO UPDATE SET value = excluded.value ` type SetDialectFlagParams struct { DialectOid int64 Key string Value string } func (q *Queries) SetDialectFlag(ctx context.Context, arg SetDialectFlagParams) error { _, err := q.db.ExecContext(ctx, setDialectFlag, arg.DialectOid, arg.Key, arg.Value) return err } const tableColumns = `-- name: TableColumns :many SELECT a.oid, a.class_oid, a.name, t.name AS type_name, a.type_oid, a.not_null, a.decl_type, a.auto_increment, a.is_primary_key, a.is_unique FROM sql_attribute a JOIN sql_class c ON c.oid = a.class_oid JOIN sql_type t ON t.oid = a.type_oid WHERE c.name = ? ORDER BY a.num ` type TableColumnsRow struct { Oid int64 ClassOid int64 Name string TypeName string TypeOid int64 NotNull int64 DeclType string AutoIncrement int64 IsPrimaryKey int64 IsUnique int64 } func (q *Queries) TableColumns(ctx context.Context, name string) ([]TableColumnsRow, error) { rows, err := q.db.QueryContext(ctx, tableColumns, name) if err != nil { return nil, err } defer rows.Close() var items []TableColumnsRow for rows.Next() { var i TableColumnsRow if err := rows.Scan( &i.Oid, &i.ClassOid, &i.Name, &i.TypeName, &i.TypeOid, &i.NotNull, &i.DeclType, &i.AutoIncrement, &i.IsPrimaryKey, &i.IsUnique, ); 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 typeArgs = `-- name: TypeArgs :many SELECT ord, label, arg_type_oid, nullable, int_value, bool_value, string_value, ident FROM sql_type_arg WHERE type_oid = ? ORDER BY ord ` type TypeArgsRow struct { Ord int64 Label string ArgTypeOid sql.NullInt64 Nullable int64 IntValue sql.NullInt64 BoolValue sql.NullInt64 StringValue sql.NullString Ident sql.NullString } func (q *Queries) TypeArgs(ctx context.Context, typeOid int64) ([]TypeArgsRow, error) { rows, err := q.db.QueryContext(ctx, typeArgs, typeOid) if err != nil { return nil, err } defer rows.Close() var items []TypeArgsRow for rows.Next() { var i TypeArgsRow if err := rows.Scan( &i.Ord, &i.Label, &i.ArgTypeOid, &i.Nullable, &i.IntValue, &i.BoolValue, &i.StringValue, &i.Ident, ); 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 typeNameByOID = `-- name: TypeNameByOID :one SELECT name FROM sql_type WHERE oid = ? ` func (q *Queries) TypeNameByOID(ctx context.Context, oid int64) (string, error) { row := q.db.QueryRowContext(ctx, typeNameByOID, oid) var name string err := row.Scan(&name) return name, err } const typeOIDByExpr = `-- name: TypeOIDByExpr :one SELECT t.oid FROM sql_type t JOIN sql_namespace ns ON ns.oid = t.namespace_oid WHERE t.expr = ?1 ORDER BY CASE ns.name WHEN 'pg_catalog' THEN 0 WHEN 'public' THEN 1 ELSE 2 END, ns.name LIMIT 1 ` func (q *Queries) TypeOIDByExpr(ctx context.Context, expr string) (int64, error) { row := q.db.QueryRowContext(ctx, typeOIDByExpr, expr) var oid int64 err := row.Scan(&oid) return oid, err } const typeOIDByExprInNamespace = `-- name: TypeOIDByExprInNamespace :one SELECT oid FROM sql_type WHERE namespace_oid = ? AND expr = ? ` type TypeOIDByExprInNamespaceParams struct { NamespaceOid int64 Expr string } func (q *Queries) TypeOIDByExprInNamespace(ctx context.Context, arg TypeOIDByExprInNamespaceParams) (int64, error) { row := q.db.QueryRowContext(ctx, typeOIDByExprInNamespace, arg.NamespaceOid, arg.Expr) var oid int64 err := row.Scan(&oid) return oid, err } const typeOIDByName = `-- name: TypeOIDByName :one SELECT t.oid FROM sql_type t JOIN sql_namespace ns ON ns.oid = t.namespace_oid WHERE t.name = ?1 AND t.family_oid IS NULL ORDER BY CASE ns.name WHEN 'pg_catalog' THEN 0 WHEN 'public' THEN 1 ELSE 2 END, ns.name LIMIT 1 ` // The family spelled name: an instance carries its family's name too, and // is found by its expression instead. func (q *Queries) TypeOIDByName(ctx context.Context, name string) (int64, error) { row := q.db.QueryRowContext(ctx, typeOIDByName, name) var oid int64 err := row.Scan(&oid) return oid, err } const typeOIDByNameInNamespace = `-- name: TypeOIDByNameInNamespace :one SELECT oid FROM sql_type WHERE namespace_oid = ? AND name = ? AND family_oid IS NULL ` type TypeOIDByNameInNamespaceParams struct { NamespaceOid int64 Name string } func (q *Queries) TypeOIDByNameInNamespace(ctx context.Context, arg TypeOIDByNameInNamespaceParams) (int64, error) { row := q.db.QueryRowContext(ctx, typeOIDByNameInNamespace, arg.NamespaceOid, arg.Name) var oid int64 err := row.Scan(&oid) return oid, err } const typeOIDsByNameInNamespaces = `-- name: TypeOIDsByNameInNamespaces :many SELECT oid, namespace_oid FROM sql_type WHERE name = ?1 AND family_oid IS NULL AND namespace_oid IN (/*SLICE:namespace_oids*/?) ` type TypeOIDsByNameInNamespacesParams struct { Name string NamespaceOids []int64 } type TypeOIDsByNameInNamespacesRow struct { Oid int64 NamespaceOid int64 } func (q *Queries) TypeOIDsByNameInNamespaces(ctx context.Context, arg TypeOIDsByNameInNamespacesParams) ([]TypeOIDsByNameInNamespacesRow, error) { query := typeOIDsByNameInNamespaces var queryParams []any queryParams = append(queryParams, arg.Name) if len(arg.NamespaceOids) > 0 { for _, v := range arg.NamespaceOids { queryParams = append(queryParams, v) } query = strings.Replace(query, "/*SLICE:namespace_oids*/?", strings.Repeat(",?", len(arg.NamespaceOids))[1:], 1) } else { query = strings.Replace(query, "/*SLICE:namespace_oids*/?", "NULL", 1) } rows, err := q.db.QueryContext(ctx, query, queryParams...) if err != nil { return nil, err } defer rows.Close() var items []TypeOIDsByNameInNamespacesRow for rows.Next() { var i TypeOIDsByNameInNamespacesRow if err := rows.Scan(&i.Oid, &i.NamespaceOid); 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 typeOIDsInCategory = `-- name: TypeOIDsInCategory :many SELECT oid FROM sql_type WHERE dialect_oid = ? AND category = ? AND family_oid IS NULL AND canonical_oid IS NULL ORDER BY oid ` type TypeOIDsInCategoryParams struct { DialectOid sql.NullInt64 Category sql.NullString } // The families of a category: an instance inherits its family's category // and an alias stands for the row it points at, so neither is listed. func (q *Queries) TypeOIDsInCategory(ctx context.Context, arg TypeOIDsInCategoryParams) ([]int64, error) { rows, err := q.db.QueryContext(ctx, typeOIDsInCategory, arg.DialectOid, arg.Category) if err != nil { return nil, err } defer rows.Close() var items []int64 for rows.Next() { var oid int64 if err := rows.Scan(&oid); err != nil { return nil, err } items = append(items, oid) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil }