# Packages
No description provided by the author
No description provided by the author
No description provided by the author
# README
Postgres
Postgres ORM.
Install
go get github.com/aacfactory/fns-contrib/databases/postgres
Usage
Deploy
app.Deply(postgres.New())
Config
See SQL.
Register driver
github.com/lib/pq
and github.com/jackc/pgx
are all supported.
Note, when use pgx
, then don't enable statements
in config.
import (
_ "github.com/lib/pq"
)
Register dialect
Add import in deploy src file.
import (
_ "github.com/aacfactory/fns-contrib/databases/postgres"
)
Define struct
See DAC.
Switch package
Use github.com/aacfactory/fns-contrib/databases/postgres
insteadof github.com/aacfactory/fns-contrib/databases/sql/dac
.
entry, err = postgres.Insert[Table](ctx, entry) // insteadof dac
Code generator in fn
Add annotation code writer
generates.New(generates.WithAnnotations(postgres.FAG()...))
Use @postgres:transaction
annotation. params are readonly
and isolation
.
- readonly: set the transaction to be readonly.
- isolation: use spec isolation. default is use isolation of config.
- ReadCommitted
- ReadUncommitted
- WriteCommitted
- RepeatableRead
- Snapshot
- Serializable
- Linearizable
// @fn some
// ... some func use transaction
// @postgres:transaction
func some(ctx context.Context, param Param) (result Result, err error) {
// ...
return
}
Use @postgres:use
annotation to switch datasource service. param is service name and mark it before @postgres:transaction
.
// @fn some
// ... some func use transaction
// @postgres:use postgres1
func some(ctx context.Context, param Param) (result Result, err error) {
// ...
return
}