Coder Social home page Coder Social logo

go-sqllib's Introduction

sqllib

Maintain a library of prepared SQL statements (*sql.Stmt)

Build Status

GoDoc

WARNING

This repository has been moved to github.com/lestrrat-go/sqllib. This repository exists so that libraries pointing to this URL will keep functioning, but this repository will NOT be updated in the future. Please use the new import path.

SYNOPSIS

import (
  "github.com/lestrrat/go-sqllib"
  "github.com/pkg/errors"
)

var lib *sqllib.Library
var db *sql.DB

func InitializeDB() {
  db, _ = sql.Open(...)

  lib = sqllib.New(db)

  // Register some SQL queries by name
  lib.Register("Simple Select", "SELECT foo FROM bar WHERE a = ?")
}

func SomeFunc(tx *sql.Tx, arg string) error {
  // When you access the SQL query again, you can ask for an
  // already prepared statement.
  stmt, err := lib.GetStmt("Simple Select")
  if err != nil {
    return errors.Wrap(err, "failed to get statement")
  }

  // Don't forget to call (*sql.Tx).Stmt on it to make a 
  // transaction-specific statement
  rows, err := tx.Stmt(stmt).Query(arg)
  ...
}

DESCRIPTION

Using prepared statements repeatedly is usually better for performance.

Keeping prepared statements around for reuse is fairly painful. This library is a very small utility to store SQL queries and refer to them by name to get back already prepared statement.

go-sqllib's People

Contributors

lestrrat avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.