// Copyright © 2025 Ory Corp // SPDX-License-Identifier: Apache-2.0 package popx import ( "fmt" "strings" "github.com/ory/pop/v6" ) func DBColumns[T any](quoter Quoter) string { return (&pop.Model{Value: new(T)}).Columns().QuotedString(quoter) } // IndexHint returns the table name including the index hint, if the database // supports it. func IndexHint(conn *pop.Connection, table string, index string) string { if conn.Dialect.Name() == "cockroach" { return table + "@" + index } // PostgreSQL and YugabyteDB do not accept CockroachDB's @index syntax. return table } func DBColumnsExcluding[T any](quoter Quoter, exclude ...string) string { cols := (&pop.Model{Value: new(T)}).Columns() for _, e := range exclude { cols.Remove(e) } return cols.QuotedString(quoter) } type ( AliasQuoter struct { Alias string Quoter Quoter } Quoter interface { Quote(key string) string } ) func (pq *AliasQuoter) Quote(key string) string { return fmt.Sprintf("%s.%s", pq.Quoter.Quote(pq.Alias), pq.Quoter.Quote(key)) } // Placeholders returns `num` placeholders ?, e.g. "?, ?, ?". // Placeholders(0) returns "". func Placeholders(num int) string { switch num { case 0: return "" case 1: return "?" default: return strings.Repeat("?, ", num-1) + "?" } }