Documentation for sq
Github Link:
github.com/bokwoon95/go-structured-query
Basics
Generating table types (
important
)
Tables, fields and predicates
Overview
Comparison Operator Reference
Query Builder Reference
SQL escape hatch
Fieldf
and
Predicatef
Building a complex query
Database connection
Struct mapping
Overview
A mental model of how
Selectx
works
Terminating
rows.Next()
early
Null values
Reusable mapper function
Mapping SQL expressions and sql.Scanner types
*Row
Reference
Fetch and Exec
Overview
ExecFlag
Getting the number of rows affected by INSERT, UPDATE or DELETE
Logging
Overview
LogFlag
Checking for specific SQL errors
Foreign Key Violation
Unique Key Violation
Query Building
SELECT
Basic Example
SELECT DISTINCT
SELECT DISTINCT ON
(postgres only)
SELECT EXISTS
Clause manipulation
INSERT
Basic Example
Getting the last inserted AUTO_INCREMENT/SERIAL ID
INSERT and ignore duplicates
Upsert
INSERT from SELECT
Binding values to columns
Clause manipulation
UPDATE
Basic Example
UPDATE with join
Multi-table UPDATE
(mysql only)
Clause manipulation
DELETE
Basic Example
DELETE with join
Multi-table DELETE
(mysql only)
Clause manipulation
Building off a common query builder
Reusing the same WHERE predicate across SELECT/UPDATE/DELETE
SQL Expressions
Aggregate functions
Window functions
Overview
Named window
Subqueries
WITH (Common Table Expressions)
ORDER BY
IN
UNION, INTERSECT, EXCEPT
CASE
calling PL/pgSQL functions
Column Types
Numbers
Strings
TIMESTAMPTZ/DATETIME
ARRAY
(postgres only)
JSON
ENUM
BYTEA, BLOB