fastsql

package module
Version: v0.0.0-...-38f65a5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2017 License: MIT Imports: 4 Imported by: 0

README

Build Status Test Coverage Code Climate GoDoc license

go-fast-sql

Package fastsql is a library which extends Go's standard database/sql library. It provides performance that's easy to take advantage of.

Even better, the fastsql.DB object embeds the standard sql.DB object meaning access to all the standard database/sql library functionality is preserved. It also means that integrating fastsql into existing codebases is a breeze.

Additional functionality inclues:

  1. Easy, readable, and performant batch insert queries using the BatchInsert method.
  2. Automatic creation and re-use of prepared statements.
  3. A convenient holder for manually used prepared statements.

##Example usage

package main

import (
	_ "github.com/go-sql-driver/mysql"
	"github.com/rmulley/go-fast-sql"
	"log"
	"net/url"
)

func main() {
	var (
		err error
		i   uint = 1
		dbh *fastsql.DB
	)

	// Create new FastSQL DB object with a flush-interval of 100 rows
	if dbh, err = fastsql.Open("mysql", "user:pass@tcp(localhost:3306)/db_name?"+url.QueryEscape("charset=utf8mb4,utf8&loc=America/New_York"), 100); err != nil {
		log.Fatalln(err)
	}
	defer dbh.Close()

	// Some loop performing SQL INSERTs
	for i <= 250 {
		if err = dbh.BatchInsert("INSERT INTO test_table(id, id2, id3) VALUES(?, ?, ?);", i, i + 1, i + 2); err != nil {
			log.Fatalln(err)
		}

		i++
	}
}

Documentation

Overview

Package fastsql is a library which extends Go's standard database/sql library. It provides performance that's easy to take advantage of.

Even better, the fastsql.DB object embeds the standard sql.DB object meaning access to all the standard database/sql library functionality is preserved. It also means that integrating fastsql into existing codebases is a breeze.

Additional functionality inclues:

1. Easy, readable, and performant batch insert queries using the BatchInsert method. 2. Automatic creation and re-use of prepared statements. 3. A convenient holder for manually used prepared statements.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	*sql.DB
	PreparedStatements map[string]*sql.Stmt
	// contains filtered or unexported fields
}

DB is a database handle that embeds the standard library's sql.DB struct.

This means the fastsql.DB struct has, and allows, access to all of the standard library functionality while also providng a superset of functionality such as batch operations, autmatically created prepared statmeents, and more.

func Open

func Open(driverName, dataSourceName string, flushInterval uint) (*DB, error)

Open is the same as sql.Open, but returns an *fastsql.DB instead.

func (*DB) BatchInsert

func (d *DB) BatchInsert(query string, params ...interface{}) (err error)

BatchInsert takes a singlular INSERT query and converts it to a batch-insert query for the caller. A batch-insert is ran every time BatchInsert is called a multiple of flushInterval times.

func (*DB) Close

func (d *DB) Close() error

Close is the same a sql.Close, but first closes any opened prepared statements.

func (*DB) FlushAll

func (d *DB) FlushAll() error

FlushAll iterates over all batch inserts and inserts them into the database.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL