Reference
Identifier Helpers
Quarry distinguishes identifiers from raw SQL and values. Use the helper types when you want tables, columns, and aliases to render with dialect-aware quoting.
Helpers
| Helper | Use it for | Notes |
|---|---|---|
quarry.T("users") |
Create a safe table identifier. | Validates the name syntactically before dialect quoting happens. |
quarry.C("email") |
Create a safe column identifier. | Useful when you want a column without a table prefix. |
quarry.T("users").As("u") |
Alias a table. | Aliases are quoted with the active dialect too. |
users.Col("email") |
Qualify a column with a table. | Produces a qualified identifier instead of raw concatenation. |
quarry.C("email").As("login_email") |
Alias a column. | Useful in SELECT lists and scan targets. |
Examples
users := quarry.T("users").As("u")
q := qq.Select(
users.Col("id"),
users.Col("email").As("login_email"),
).From(users)
sql, args, err := q.ToSQL()
// SELECT "u"."id", "u"."email" AS "login_email" FROM "users" AS "u"
What counts as safe
- Helper names are validated locally, not against the database or migrations.
- The check is syntactic: non-empty, starts with a letter or underscore, and then uses letters, digits, or underscores.
- Plain strings still work, but they are treated as raw SQL fragments.
- Dialect quoting is explicit, so Postgres, MySQL, and SQLite render differently.