rootx

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2015 License: MIT Imports: 3 Imported by: 0

README

WillowTree is Hiring!

Want to write Go for mobile applications? Want to write anything else for mobile applications? Check out our openings!

RootX

Helper functions and code generation tools for https://github.com/jmoiron/sqlx.

Blog post coming soon!

Installation

go get github.com/willowtreeapps/rootx/...

Command Usage

$ rootx-gen -h
Usage of rootx-gen:
  -dir string
    	Directory containing sql files
  -dryRun
    	Output to STDOUT instead of writing files
  -formatter string
    	Command to use to format source code (gofmt, goimports) (default "goimports")
  -mode string
    	Mode for generator: code | mock | interface (default "code")
  -o string
    	Output file
  -pkg string
    	Go package to use
  -psql
    	Whether to use Postgres insert strategy, using "RETURNING id" (default true)
  -readType string
    	Type of instance to use for read methods
  -writeType string
    	Type of instance to use for write methods

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteOne

func DeleteOne(db Rootx, sqlKey string, args ...interface{}) error

DeleteOne deletes a single instance

func Exec

func Exec(db Rootx, sqlKey string, args ...interface{}) error

Exec executes a statement

func Exists

func Exists(db Rootx, sqlKey string, args ...interface{}) (bool, error)

Exists checks to see if the item exists by a COUNT query

func Insert

func Insert(db Rootx, sqlKey string, args ...interface{}) (int64, error)

Insert inserts a single instance

func InsertPsql

func InsertPsql(db Rootx, sqlKey string, args ...interface{}) (int64, error)

InsertPsql inserts a single instance

func ScanOne

func ScanOne(instance interface{}, rows *sqlx.Rows) error

ScanOne returns the instance, if any, returned from sql query

func SelectAll

func SelectAll(db Rootx, sqlKey string, instances interface{}, args ...interface{}) error

SelectAll selects a slice of structs

func SelectOne

func SelectOne(db Rootx, sqlKey string, instance interface{}, args ...interface{}) error

SelectOne selects a single struct

func UpdateOne

func UpdateOne(db Rootx, sqlKey string, args ...interface{}) error

UpdateOne updates a single instance

Types

type Error

type Error struct {
	Key      string
	Where    string
	SQLError error
}

Error defines an error that can occur in Rootx helper methods.

This is useful to inspect the specific key an error occurred on.

func (*Error) Error

func (e *Error) Error() string

type Rootx

type Rootx interface {
	SQL(key string) (query string)

	Exec(query string, args ...interface{}) (sql.Result, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
	Select(instances interface{}, query string, args ...interface{}) error
	Get(instance interface{}, query string, args ...interface{}) error
}

Rootx defines an interface that needs to be implemented to take advantage of the Rootx helper methods.

With the exception of SQL, which is used to get SQL queries by key, these are provided by github.com/jmoiron/sqlx's DB and TX.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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