dbless

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2019 License: MIT Imports: 7 Imported by: 4

README

go-dbless

Travis godoc License Go Report Card cover.run

Database library with less complexity and less modeling.

Install

go get -u github.com/ddliu/go-dbless

Usage

Basic
  • DBInsert
  • DBUpdate
  • DBDelete
  • DBGetRows
  • DBGetRow
  • DBGetScalar
Resource
package main
import github.com/ddliu/go-dbless

func main() {
    db := somedb()

    resource := dbless.Resource{
        Name: "user",
        Timestamp: true,
        DB: db,
    }

    id, err := resource.Save(dbless.Record{
        "username": "ddliu",
        "password": "123456",
    })

    user, err := record.Get(id)

    listing := resource.List(dbless.ListInput{
        Pagination: dbless.Pagination {
            PageSize: 20,
            Page: 1,
        },
    })
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DBDelete

func DBDelete(db *sql.DB, table string, where string, args ...interface{}) (uint64, error)

func DBGetRow

func DBGetRow(db *sql.DB, sql string, args ...interface{}) (map[string]interface{}, error)

func DBGetRows

func DBGetRows(db *sql.DB, sql string, args ...interface{}) ([]map[string]interface{}, error)

func DBInsert

func DBInsert(db *sql.DB, table string, row map[string]interface{}) (uint64, error)

func DBScalar

func DBScalar(db *sql.DB, sql string, args ...interface{}) (uint64, error)

func DBUpdate

func DBUpdate(db *sql.DB, table string, row map[string]interface{}, where string, args ...interface{}) (uint64, error)

func IsRecordNotFound

func IsRecordNotFound(err error) bool

Types

type Field

type Field struct {
	Name        string `json:"name"`
	Title       string `json:"title"`
	Description string `json:"description"`
}

type ListInput

type ListInput struct {
	Pagination Pagination `json: "pagination"`
}

type ListOutput

type ListOutput struct {
	Pagination
	List []Record `json:"list"`
}

type PagedRows

type PagedRows struct {
	Pagination
	List []map[string]interface{} `json:"list"`
}

func DBGetPaging

func DBGetPaging(db *sql.DB, pageSize uint, page uint, sql string, args ...interface{}) (*PagedRows, error)

type Pagination

type Pagination struct {
	PageSize  uint `json:"page_size"`
	Page      uint `json:"page"`
	PageTotal uint `json:"page_total"`
	Total     uint `json:"total"`
}

func NewPagination

func NewPagination(pageSize, page uint) *Pagination

func (*Pagination) GetOffsetLimit

func (p *Pagination) GetOffsetLimit() (uint, uint)

func (*Pagination) SetTotal

func (p *Pagination) SetTotal(total uint)

func (*Pagination) Valid

func (p *Pagination) Valid()

type Record

type Record map[string]interface{}

func (Record) ID

func (r Record) ID() uint64

type RecordNotFoundError

type RecordNotFoundError struct {
}

func (RecordNotFoundError) Error

func (e RecordNotFoundError) Error() string

type Resource

type Resource struct {
	Name      string  `json:"name"`
	Title     string  `json:"title"`
	Fields    []Field `json:"fields"`
	Timestamp bool    `json:"timestamp"`
	DB        *sql.DB `json:"-"`
}

func (Resource) Delete

func (r Resource) Delete(id uint64) error

func (Resource) Get

func (r Resource) Get(id uint64) (Record, error)

func (Resource) List

func (r Resource) List(input ListInput) (*ListOutput, error)

func (Resource) Save

func (r Resource) Save(record Record) (uint64, error)

Directories

Path Synopsis
driver
mysql Module
postgres Module
sqlite Module
test module

Jump to

Keyboard shortcuts

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