Skip to main content

Columns

The orm.Columns type is a bob expression.

To create a new columns list, use orm.NewColumns(names ...string). You can then add the parent table with WithParent()

orm.NewColumns("id", "name", "email").WithParent("public.users")
-- table_alias.column_name
"public.users"."id" AS "id",
"public.users"."name" AS "name",
"public.users"."email" AS "email"

It has many convenient methods to manipulate the columns list.

Only

Returns the column list with ONLY the given column names.

userView.Columns().Only("email")
"public.users"."email" AS "email",

Except

Returns the columns list w ithout the given column names.

userView.Columns().Except("email")
"public.users"."id" AS "id",
"public.users"."name" AS "name",

WithParent

Changes the parent of the column list. For example if selecting with an alias.
Multiple strings are quoted and joined with a dot.

userView.Columns().WithParent("backup", "users_old")
"backup"."users_old"."id" AS "id",
"backup"."users_old"."name" AS "name",
"backup"."users_old"."email" AS "email"

WithPrefix

Sets a prefix for all columns, useful for joins with duplicate column names.

userView.Columns().WithPrefix("users.")
"public.users"."id" AS "users.id",
"public.users"."name" AS "users.name",
"public.users"."email" AS "users.email"