Skip to content

miguelpragier/pgkebab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub GitHub Go Report Card Go Version

PGKebab

GOLang PostgreSQL Helper Over PQ

Makes PostgreSQL handling as easy and simple as GOlang
Replace heavy ORMs and dense routines with simple SQL queries

PGKebab

Simple Sample
package main

import (
	"fmt"
	"github.com/miguelpragier/pgkebab"
	"log"
)

func main() {
	const (
		connectionTimeout                  = 10
		executiontionTimeout               = 10
		connectionMaxAttempts              = 5
		connectionMaxMinutesRetrying       = 5
		secondsBetweenReconnectionAttempts = 10
		debugLogPrint                      = true
	)

	var (
		cs         = pgkebab.ConnStringEnvVar("{YOURAPPCONNECTIONSTRING}")
		opts       = pgkebab.Options(cs, connectionTimeout, executiontionTimeout, connectionMaxAttempts, connectionMaxMinutesRetrying, secondsBetweenReconnectionAttempts, debugLogPrint)
		customerID = 1
	)

	db, errcnx := pgkebab.NewConnected(opts)

	if errcnx != nil {
		log.Fatal(errcnx)
	}

	if row, err := db.GetOne("SELECT name, status_id FROM customers WHERE id=$1", customerID); err != nil {
		log.Fatal(err)
	} else {
		fmt.Println("the customer", row.String("name"), "has status", row.Int64("status_id"))
	}

	if n, err := db.GetCount("customers"); err != nil {
		log.Fatal(err)
	} else {
		fmt.Println("table customer counts", n, "rows")
	}
}
Dependencies:

pq - Pure Go Postgres driver for database/sql


Releases

No releases published

Packages

No packages published

Languages