mysequel

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2020 License: MIT Imports: 6 Imported by: 6

README

mysequel

MySQL Database CRUD Helper for Go

Documentation

Overview

Package mysequel provides helpers to insert data directly to database

Package mysequel provides helpers to insert data directly to database

Package mysequel provides helpers to insert data directly to database

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Insert

func Insert(t InsertTable) (int64, error)

Insert prepares INSERT statement and executes it

func NewNullString

func NewNullString(s string) sql.NullString

NewNullString fuctions returns a NULL if the passed string is empty

func QueryToStructs

func QueryToStructs(dest interface{}, db QueryRunner, q string, args ...interface{}) error

QueryToStructs takes struct slice pointer, database instance, SQL query and placeholders and returns populates the slice with the result structs.

func Update

func Update(t UpdateTable) (int64, error)

Update prepares UPDATE statement and executes it

Types

type FormTable

type FormTable struct {
	TableName string
	RCols     []string
	OCols     []string
	Form      url.Values
	Tx        *sql.Tx
}

FormTable holds data to be inserted

func (FormTable) Cols

func (t FormTable) Cols() []string

Cols returns column names

func (FormTable) Name

func (t FormTable) Name() string

Name returns table name

func (FormTable) Transaction

func (t FormTable) Transaction() *sql.Tx

Transaction returns transaction object to query results from

func (FormTable) Values

func (t FormTable) Values() []interface{}

Values returns column values

type InsertTable

type InsertTable interface {
	Name() string
	Cols() []string
	Values() []interface{}
	Transaction() *sql.Tx
}

InsertTable interface define table structure perform INSERT queries

type QueryRunner

type QueryRunner interface {
	Query(string, ...interface{}) (*sql.Rows, error)
}

QueryRunner interface allows QueryToStructs to be passed in *sql.DB and *sql.Tx instances at the same time

type Table

type Table struct {
	TableName string
	Columns   []string
	Vals      []interface{}
	Tx        *sql.Tx
}

Table holds data to be inserted

func (Table) Cols

func (t Table) Cols() []string

Cols returns column names

func (Table) Name

func (t Table) Name() string

Name returns table name

func (Table) Transaction

func (t Table) Transaction() *sql.Tx

Transaction returns transaction object to query results from

func (Table) Values

func (t Table) Values() []interface{}

Values returns column values

type UdpateTable

type UdpateTable interface {
	InsertTable
	WhereCols() []string
	WhereValues() []interface{}
}

UdpateTable interface define table structure perform UPDATE queries

type UpdateTable

type UpdateTable struct {
	Table
	WColumns []string
	WVals    []string
}

UpdateTable holds data to be updated

func (UpdateTable) WhereCols

func (t UpdateTable) WhereCols() []string

WhereCols returns columns included in where clause

func (UpdateTable) WhereValues

func (t UpdateTable) WhereValues() []interface{}

WhereValues returns values included in where clause

Jump to

Keyboard shortcuts

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