Go-postgres - go-postgres library provide NoSQL functionality which can execute queries with pool of connections

GO Postgres

go-postgres library provide NoSQL functionality which can execute queries with pool of connections.

What is this repository for?

  • Establish postgres connection pool
  • Execute the SQL queries

How do I get set up?

Establish Postgres Connection

package main

import (
	"fmt"
	"bitbucket.org/mybudget-dev/go-postgres"
)

func main() {
	conf := gopostgres.DBConfig{
		User:     "User",
		Password: "Password",
		Host:     "<<Host>>",
		Port:     "<<PORT>>",
		Database: "Database",
	}
	DBPool, err := gopostgres.NewDBPool(conf)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	defer DBPool.Close()

}

Postgres Insert

package main

import (
	"context"
	"fmt"
	"bitbucket.org/mybudget-dev/go-postgres"
)

func main() {
	conf := gopostgres.DBConfig{
		User:     "User",
		Password: "Password",
		Host:     "<<Host>>",
		Port:     "<<PORT>>",
		Database: "Database",
	}
	sql, err := gopostgres.NewDBPool(conf)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	defer sql.Close()

	// context 
	ctx := context.Background()

	// insert data into postgres
	data := "data"
	// Transaction opt is optional and you can configure DB isolation levels  
	transaction, err := sql.BeginTransaction(ctx, nil)
	if err != nil {
		return
	}
	userQuery :=
		fmt.Sprintf(`INSERT INTO "%s"(data) VALUES($1)`,
			"table")
	statement, err := transaction.PrepareContext(ctx, userQuery)
	if statement != nil {
		defer statement.Close()
	} else {
		fmt.Println(err.Error())
		return
	}
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	_, err = statement.ExecContext(ctx, &data)
	if err != nil {
		if errorTransaction := transaction.Rollback(); errorTransaction != nil {
			fmt.Println(err.Error())
		}
	}
}

Postgres Get

package main

import (
	"context"
	"fmt"
	"bitbucket.org/mybudget-dev/go-postgres"
)

func main() {
	conf := gopostgres.DBConfig{
		User:     "User",
		Password: "Password",
		Host:     "<<Host>>",
		Port:     "<<PORT>>",
		Database: "Database",
	}
	sql, err := gopostgres.NewDBPool(conf)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	defer sql.Close()

	// context 
	ctx := context.Background()

	// get data from postgres
	key := 1
	query := fmt.Sprintf(`SELECT data FROM "%s" WHERE key=$1  ;`, "table")
	statementOfLocation, err := sql.Prepare(ctx, query)
	if statementOfLocation != nil {
		defer statementOfLocation.Close()
	}
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	row, err := statementOfLocation.QueryContext(ctx, key)
	if row != nil {
		defer row.Close()
	}
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	var data interface{}
	for row.Next() {
		err = row.Scan(&data)
		if err != nil {
			fmt.Println(err.Error())
			return
		}
	}
}
Similar Resources

sqlbench measures and compares the execution time of one or more SQL queries.

sqlbench sqlbench measures and compares the execution time of one or more SQL queries. The main use case is benchmarking simple CPU-bound query varian

Dec 6, 2022

SQL API is designed to be able to run queries on databases without any configuration by simple HTTP call.

SQL API SQL API is designed to be able to run queries on databases without any configuration by simple HTTP call. The request contains the DB credenti

Dec 2, 2022

A database connection wrapper to cache prepared statements by transforming queries to use with array arguments.

sqlpp sqlpp is a sql(MySQL and PostgreSQL) database connection wrapper to cache prepared statements by transforming queries ("...in (?)...", []) to us

Feb 9, 2022

Parses a file and associate SQL queries to a map. Useful for separating SQL from code logic

goyesql This package is based on nleof/goyesql but is not compatible with it any more. This package introduces support for arbitrary tag types and cha

Oct 20, 2021

A simple Golang-based application that queries a PostgreSQL database

Qwik-E-Mart Demo App A simple Golang-based application that queries a PostgreSQL database named qwikemart to read and return customer data stored in t

Nov 6, 2021

Get data from .csv files use SQL-like queries.

csvql Get data from .csv files use SQL-like queries. Задание Необходимо написать консольную программу, которая по заданному клиентом запросу осуществл

Dec 7, 2021

Opionated sql formatter for use with .go files containing backticked queries

fumpt-the-sql Opionated sql formatter for use with .go files containing backticked queries. Uses https://sqlformat.darold.net/ for the actual sql form

Dec 10, 2021

This Service collects slow queries and returns them in response.

pgsql-api-go This Service collects slow queries and returns them in response. Status This service is the very first version of the project. App is up

Dec 30, 2021

Run SQL queries against JSON, CSV, Excel, Parquet, and more.

Run SQL queries against JSON, CSV, Excel, Parquet, and more This is a CLI companion to DataStation (a GUI) for running SQL queries against data files.

Dec 31, 2022
A reverse proxy for postgres which rewrites queries.

pg-rewrite-proxy A reverse proxy for postgres which rewrites queries. Arbitrary rewriting is supported by supplying an LUA script to the proxy applica

Dec 12, 2022
pggen - generate type safe Go methods from Postgres SQL queries

pggen - generate type safe Go methods from Postgres SQL queries pggen is a tool that generates Go code to provide a typesafe wrapper around Postgres q

Jan 3, 2023
Querycrate - A simple library that loads and keeps SQL queries from files

QueryCrate A simple library for loading & getting string queries from files. How

Feb 15, 2022
Basic LDAP v3 functionality for the GO programming language.

Basic LDAP v3 functionality for the GO programming language. The library implements the following specifications: https://tools.ietf.org/html/rfc4511

Dec 31, 2022
Database wrapper that manage read write connections

rwdb Database wrapper that manage read write connections Install go get github.com/andizzle/rwdb Create connections package main import "github.com/

Dec 10, 2022
Interactive terminal user interface and CLI for database connections. MySQL, PostgreSQL. More to come.
Interactive terminal user interface and CLI for database connections. MySQL, PostgreSQL. More to come.

?? dbui dbui is the terminal user interface and CLI for database connections. It provides features like, Connect to multiple data sources and instance

Jan 5, 2023
This package can parse date match expression, which used by ElasticSearch

datemath-parser this package is pure go package, this package can parse date match expression, which used by ElasticSearch. Date Math Definition you c

Jan 8, 2022
A tool to run queries in defined frequency and expose the count as prometheus metrics. Supports MongoDB and SQL
A tool to run queries in defined frequency and expose the count as prometheus metrics. Supports MongoDB and SQL

query2metric A tool to run db queries in defined frequency and expose the count as prometheus metrics. Why ? Product metrics play an important role in

Jul 1, 2022
write APIs using direct SQL queries with no hassle, let's rethink about SQL

SQLer SQL-er is a tiny portable server enables you to write APIs using SQL query to be executed when anyone hits it, also it enables you to define val

Jan 7, 2023