db

package module
v0.0.0-...-8c01965 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2018 License: MIT Imports: 7 Imported by: 2

README

Build Status codecov Go Report Card

db

Very simple database package based on reform.

import "github.com/compo-io/db"

Usage

var (

	// ErrNoRows is returned when no rows are found
	ErrNoRows = reform.ErrNoRows

	// ErrInitialized is returned when the database is already initialized
	ErrInitialized = errors.New("database already initialized")
)
func Get
func Get() *reform.DB

Get returns database connection if the package was initialized using Init() method, returns nil otherwise. Make sure your are calling Init() before any queries.

func Init
func Init(dsn *string, driver *string) error

Init is initializing the database using optional dsn and driver. It will use default values if nil is passed. This method can only be called once, or will return an error ErrInitialized.

Example

package main

import (
    "log"

    "github.com/compo-io/db"
)

func main() {
    if err := db.Init(nil,nil); err != nil {
        log.Fatal(err)
    }

    db.Get().Query("SELECT * FROM users WHERE id = ?", 1)
}

Documentation

Overview

Package db is a very simple database package based on reform(https://github.com/go-reform/reform).

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNoRows is returned when no rows are found
	ErrNoRows = reform.ErrNoRows

	// ErrInitialized is returned when the database is already initialized
	ErrInitialized = errors.New("database already initialized")
)

Functions

func Get

func Get() *reform.DB

Get returns database connection if the package was initialized using Init() method, returns nil otherwise. Make sure your are calling Init() before any queries.

func Init

func Init(dsn *string, driver *string) error

Init is initializing the database using optional dsn and driver. It will use default values if nil is passed. This method can only be called once, or will return an error ErrInitialized.

func IsErrNoRows

func IsErrNoRows(err error) bool

IsErrNoRows returns true if err == ErrNoRows

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL