dbpro

package module
v0.0.0-...-21abb5d Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: MIT Imports: 12 Imported by: 0

README

dbpro

dbpro is a library which provides a set of utility function to simplify the task of generating data in database tables.

install

go get github.com/tendant/dbpro

usage

type Person struct {
    FirstName string
    LastName  string
    Email     string
}

person := Person{
    FirstName: "test first name"
    LastName: "test last name"
    Email: "test@example.com"
}

// query, err := dbpro.GenInsertQuery("postgres", "person"", person)

// vals, err := dbpro.GenInsertValues(person)

// rows, err := db.NamedQuery(stmt, vals)

db, err := sqlx.Connect("postgres", "user=foo dbname=bar sslmode=disable")
if err != nil {
     log.Fatalln(err)
}

id, err := dbpro.InsertRow(db, "person", person)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenInsertQuery

func GenInsertQuery(driverName string, table string, values interface{}, exclude ...string) (string, error)

func GenInsertValues

func GenInsertValues(entity interface{}, exclude ...string) (map[string]interface{}, error)

func InsertRow

func InsertRow(db *sqlx.DB, table string, entity interface{}, exclude ...string) (int64, error)

func Now

func Now() string

func RandomBit

func RandomBit() int

Types

This section is empty.

Jump to

Keyboard shortcuts

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