/pegi

An sqlx wrapper mainly for PostgreSQL

Primary LanguageGoMIT LicenseMIT

Pegi

PkgGoDev Build Status

A sqlx wrapper mainly for PostgreSQL.

go get -u -v github.com/kakilangit/pegi

Example:

package main

import (
	"context"
	"database/sql"
	"log"

	"github.com/jmoiron/sqlx"
	"github.com/kakilangit/pegi"
)

func main() {
	db := pegi.NewDB(&sqlx.DB{}, &sql.TxOptions{})
	if err := db.RunInTransaction(context.Background(), func(ctx context.Context) error {
		var id string
		if err := db.GetAccess(ctx).Get(&id, "SELECT id FROM users WHERE name = ?", "name"); err != nil {
			return err
		}

		_, err := db.QueryBuilder(ctx).Update("users").Set("address", "new address").Where("id = ?", id).Exec()
		return err
	}); err != nil {
		log.Fatal(err)
	}
}