Files
upstream-ory-kratos/oryx/popx/db_columns.go
upstream-mirror c60cc7ca75
Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
snapshot of https://github.com/ory/kratos.git (master, 2026-09-15; blobs > 131072B omitted)
2026-09-15 21:19:12 +05:00

61 lines
1.3 KiB
Go

// 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) + "?"
}
}