dbless

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2020 License: MIT Imports: 10 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
Schema
  • List databases
  • List tables
  • List columns
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 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 DB added in v0.2.0

type DB struct {
	DB     *sql.DB
	Driver Driver
}

func New added in v0.2.0

func New(driverName string, db *sql.DB) *DB

func Open added in v0.2.0

func Open(driverName, dsn string) (*DB, error)

func (*DB) Delete added in v0.2.0

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

func (*DB) GetPaging added in v0.2.0

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

func (*DB) GetRow added in v0.2.0

func (db *DB) GetRow(sql string, args ...interface{}) (Record, error)

func (*DB) GetRows added in v0.2.0

func (db *DB) GetRows(sqlStr string, args ...interface{}) ([]Record, error)

func (*DB) Insert added in v0.2.0

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

func (*DB) ListColumns added in v0.2.0

func (db *DB) ListColumns(dbname, tablename string) ([]*sql.ColumnType, error)

func (*DB) ListDatabases added in v0.2.0

func (db *DB) ListDatabases() ([]string, error)

func (*DB) ListTables added in v0.2.0

func (db *DB) ListTables(dbname string) ([]string, error)

func (*DB) Scalar added in v0.2.0

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

func (*DB) Update added in v0.2.0

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

type Driver added in v0.2.0

type Driver interface {
	Name() string
	QuoteIdentifier(string) string
	ListDatabases(db *sql.DB) ([]string, error)
	ListTables(db *sql.DB, dbname string) ([]string, error)
	ListColumns(db *sql.DB, dbname string, tablename string) ([]*sql.ColumnType, error)
}

type DriverNotImplementedError added in v0.2.0

type DriverNotImplementedError struct {
}

func (DriverNotImplementedError) Error added in v0.2.0

type Field

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

type Filter added in v0.1.3

type Filter map[string]interface{}

func (Filter) GetWhere added in v0.1.6

func (f Filter) GetWhere() (string, []interface{})

type ListInput

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

type ListOutput

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

type MysqlDriver added in v0.2.0

type MysqlDriver struct{}

func (*MysqlDriver) ListColumns added in v0.2.0

func (m *MysqlDriver) ListColumns(db *sql.DB, dbname string, tablename string) ([]*sql.ColumnType, error)

func (*MysqlDriver) ListDatabases added in v0.2.0

func (m *MysqlDriver) ListDatabases(db *sql.DB) ([]string, error)

func (*MysqlDriver) ListTables added in v0.2.0

func (m *MysqlDriver) ListTables(db *sql.DB, dbname string) ([]string, error)

func (*MysqlDriver) Name added in v0.2.0

func (m *MysqlDriver) Name() string

func (*MysqlDriver) QuoteIdentifier added in v0.2.0

func (m *MysqlDriver) QuoteIdentifier(v string) string

type NoDriverError added in v0.2.0

type NoDriverError struct {
}

func (NoDriverError) Error added in v0.2.0

func (e NoDriverError) Error() string

type PagedRows

type PagedRows struct {
	Pagination
	List []Record `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 PostgresDriver added in v0.2.0

type PostgresDriver struct {
}

func (*PostgresDriver) ListColumns added in v0.2.0

func (m *PostgresDriver) ListColumns(db *sql.DB, dbname string, tablename string) ([]*sql.ColumnType, error)

func (*PostgresDriver) ListDatabases added in v0.2.0

func (m *PostgresDriver) ListDatabases(db *sql.DB) ([]string, error)

func (*PostgresDriver) ListTables added in v0.2.0

func (m *PostgresDriver) ListTables(db *sql.DB, dbname string) ([]string, error)

func (*PostgresDriver) Name added in v0.2.0

func (m *PostgresDriver) Name() string

func (*PostgresDriver) QuoteIdentifier added in v0.2.0

func (m *PostgresDriver) QuoteIdentifier(v string) string

type Record

type Record map[string]interface{}

func DBGetRow

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

func DBGetRows

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

func (Record) ID

func (r Record) ID() uint64

func (Record) Unmarshal added in v0.1.7

func (r Record) Unmarshal(input interface{}) error

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"`
	Meta      string  `json:"meta"`
	DB        *sql.DB `json:"-"`
}

func (Resource) Delete

func (r Resource) Delete(filter interface{}) error

func (Resource) Get

func (r Resource) Get(filter interface{}) (Record, error)

func (Resource) List

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

func (Resource) Save

func (r Resource) Save(record Record, filter ...Filter) (uint64, error)

type SqlServerDriver added in v0.2.0

type SqlServerDriver struct {
}

func (*SqlServerDriver) ListColumns added in v0.2.0

func (m *SqlServerDriver) ListColumns(db *sql.DB, dbname string, tablename string) ([]*sql.ColumnType, error)

func (*SqlServerDriver) ListDatabases added in v0.2.0

func (m *SqlServerDriver) ListDatabases(db *sql.DB) ([]string, error)

func (*SqlServerDriver) ListTables added in v0.2.0

func (m *SqlServerDriver) ListTables(db *sql.DB, dbname string) ([]string, error)

func (*SqlServerDriver) Name added in v0.2.0

func (m *SqlServerDriver) Name() string

func (*SqlServerDriver) QuoteIdentifier added in v0.2.0

func (m *SqlServerDriver) QuoteIdentifier(v string) string

type Sqlite3Driver added in v0.2.0

type Sqlite3Driver struct {
}

func (*Sqlite3Driver) ListColumns added in v0.2.0

func (m *Sqlite3Driver) ListColumns(db *sql.DB, dbname string, tablename string) ([]*sql.ColumnType, error)

func (*Sqlite3Driver) ListDatabases added in v0.2.0

func (m *Sqlite3Driver) ListDatabases(db *sql.DB) ([]string, error)

func (*Sqlite3Driver) ListTables added in v0.2.0

func (m *Sqlite3Driver) ListTables(db *sql.DB, dbname string) ([]string, error)

func (*Sqlite3Driver) Name added in v0.2.0

func (m *Sqlite3Driver) Name() string

func (*Sqlite3Driver) QuoteIdentifier added in v0.2.0

func (m *Sqlite3Driver) QuoteIdentifier(v string) string

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