Documentation
¶
Index ¶
- func WhereID[Col ColName](b *Builder[Col])
- type Builder
- func (b *Builder[Col]) Delete(schema, table string, wf WhereFunc[Col], returnColumns ...Col)
- func (b *Builder[Col]) Insert(schema, table string, insertColumns []string, returnColumns ...Col)
- func (b *Builder[Col]) Reset()
- func (b *Builder[Col]) Select(schema, table string, columns []Col, wf WhereFunc[Col], ...)
- func (b *Builder[Col]) Update(schema, table string, updateColumns []string, wf WhereFunc[Col], ...)
- func (b *Builder[Col]) WriteColumnSpec(columns []Col)
- func (b *Builder[Col]) WriteIdentifier(schema, table string)
- func (b *Builder[Col]) WritePosArgs(n int)
- func (b *Builder[Col]) WriteReturnClause(columns []Col)
- type ColName
- type Direction
- type OrderWriter
- type Pool
- type WhereFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Builder ¶
Builder for queries
func (*Builder[Col]) Delete ¶
Delete builds a delete query. The WHERE clause must be written by the passed WhereFunc, which will not be called if nil. WARNING: a nil WhereFunc will result in deletion of all records in a table! See WriteReturnClause on when and how the RETURNING clause is written.
DELETE FROM "public"."simple" WHERE "id" = $1 RETURNING ("id, "title", "data");
func (*Builder[Col]) Insert ¶
Insert builds an insert query. See WriteReturnClause on when and how the RETURNING clause is written.
INSERT INTO "public"."simple_rw" ("id", "title") VALUES ($1, $2) RETURNING "id";
func (*Builder[Col]) Select ¶
func (b *Builder[Col]) Select(schema, table string, columns []Col, wf WhereFunc[Col], orderBy OrderWriter[Col], limit int64)
Select builds a select query. The WHERE clause must be written by the passed WhereFunc, which will not be called if nil. The ORDER By clause is written when orderBy is not nil. The LIMIT clause is only written when greater than 0.
SELECT "id", "title", "price" FROM "public"."products" WHERE "id" = $1 ORDER BY "id" LIMIT 1;
func (*Builder[Col]) Update ¶
func (b *Builder[Col]) Update(schema, table string, updateColumns []string, wf WhereFunc[Col], returnColumns ...Col)
Update builds a update query. The WHERE clause must be written by the passed WhereFunc, which will not be called if nil. WARNING: a nil WhereFunc will result in updates of all records in a table! See WriteReturnClause on when and how the RETURNING clause is written.
UPDATE "public"."simple" SET "title" = $1, "data" = $2 WHERE "id" = $3 RETURNING ("title", "data");
func (*Builder[Col]) WriteColumnSpec ¶
func (b *Builder[Col]) WriteColumnSpec(columns []Col)
WriteColumnSpec writes the column specifier to the query. All column names are doube-quoted and comma seperated.
func (*Builder[Col]) WriteIdentifier ¶
WriteIdentifier writes the full identifier of a table. This includes the schema, if it is not empty. Written names will be quoted.
func (*Builder[Col]) WritePosArgs ¶
WritePosArgs writes n amount of positional arguments to the query, in the form of "$1, $2". WritePosArgs can be called multiple times while building a query, and all position values in the resulting query will be uniquely incremented values.
func (*Builder[Col]) WriteReturnClause ¶
func (b *Builder[Col]) WriteReturnClause(columns []Col)
WriteReturnClause writes a RETURNING clause with a column spec. If columns has zero length, nothing will be written (no-op).
type ColName ¶
ColName is the generic interface for column name specification. Typically, one can use a protobuf enum for column names. The enum entries have a String method, implementing this interface.
type OrderWriter ¶
type OrderWriter[Col ColName] interface { // contains filtered or unexported methods }
OrderWriter writen the ORDER BY ... [ASC|DESC] clause.
func Order ¶
func Order[Col ColName](direction Direction, columns ...Col) OrderWriter[Col]
Order returns an OrderWriter, which writes the ORDER BY "col1", "col2", "colN" [ASC|DESC] clause.
type Pool ¶
type Pool[Col ColName] struct { // contains filtered or unexported fields }
Pool utilizes a sync.Pool for efficient re-use of Builders.
type WhereFunc ¶
WhereFunc are callback functions that writes the "WHERE" clause to a query.
func WhereIDInFunc ¶
WhereIDInFunc returns a function which writes a where clause in the form:
WHERE "id" IN $1, $2, $N...