# README
sqlapi
sqlgen generates SQL statements and database helper functions from your Go structs. It can be used in place of a simple ORM or hand-written SQL. sqlapi (this package) supports the generated code.
See the demo directory for examples. Look in the
generated files *_sql.go
and the hand-crafted files (hook.go
, issue.go
, user.go
).
Currently, support is included for MySQL, PostgreSQL and SQLite. Other dialects can be added relatively easy - send a Pull Request!
Features
package constraint
- Representations for inter-table constraints.
package require
- Predicates allowing easier detection of unexpected results from SELECTS, e.g. when the result set size is not exactly one.
package dialect
- SQL dialects for SQLite, MySQL, PostgreSQL and its pgx variant. This provides some conditional SQL generation and also
package where
- Fluent construction of WHERE and HAVING clauses: this is now [github.com/rickb777/where](https://github .com/rickb777/where). This also provides control over identifier quoting, e.g. ANSI SQL, back-ticks, etc.
Install
Install with this command:
go get github.com/rickb777/sqlapi
Please continue reading about sqlgen2.
# Packages
Package constraint provides types and methods to support foreign-key relationshipd between database tables.
No description provided by the author
Package sqlapi contains a small API for a tool (sqlgen2) that generates SQL functions for specified struct types.
Package require provides simple constraints to assist with detecting errors in database queries that arise from the wrong number of result (for example no result or too many results).
No description provided by the author
No description provided by the author
No description provided by the author
Package vanilla provides a re-usable table API.
# Functions
Connect opens a database connection and pings the server.
ConnectEnv connects to the database server using environment variables: DB_URL, DB_DRIVER and DB_QUOTE.
ListTables gets all the table names in the database/schema.
MustConnect is as per Connect but with a fatal termination on error.
MustConnectEnv is as per ConnectEnv but with a fatal termination on error.
Named creates NamedArg values; it is synonymous with sql.Named().
NamedArgString converts the argument to a string of the form "name=value".
No description provided by the author
No description provided by the author
WrapDB wraps a *sql.DB as SqlDB.
WrapRows wraps a *sql.Rows result so that its data can be scanned into a series of maps, one for each row.
# Interfaces
CanPostGet is implemented by value types that need a hook to run just after their data is fetched from the database.
CanPreInsert is implemented by value types that need a hook to run just before their data is inserted into the database.
CanPreUpdate is implemented by value types that need a hook to run just before their data is updated in the database.
Execer is a precis of *sql.DB and *sql.Tx (see database/sql).
Getter provides the core methods for reading information from databases.
Logger provides the specialised logging operations within this API.
SqlDB is able to make queries and begin transactions.
SqlRow is a precis of *sql.Row.
SqlRows is a precis of *sql.Rows.
SqlTx is a precis of *sql.Tx.
No description provided by the author
Table provides the generic features of each generated table handler.
TableCreator is a table with create/delete/truncate methods.
TableWithIndexes is a table creator with create/delete methods for the indexes.