Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kakilangit/pegi

An sqlx wrapper mainly for PostgreSQL
https://github.com/kakilangit/pegi

go postgresql query-builder sqlx transaction-runner

Last synced: 21 days ago
JSON representation

An sqlx wrapper mainly for PostgreSQL

Awesome Lists containing this project

README

        

# Pegi

[![PkgGoDev](https://pkg.go.dev/badge/github.com/kakilangit/pegi)](https://pkg.go.dev/github.com/kakilangit/pegi)
[![Build Status](https://app.travis-ci.com/kakilangit/pegi.svg?branch=main)](https://app.travis-ci.com/github/kakilangit/pegi)

A sqlx wrapper mainly for PostgreSQL.

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

Example:

```go
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)
}
}

```