sql

package module
v0.0.0-...-2fb3e27 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

README

sqlx

Golang's lightweight ORM Library

Overview

  • Part-Featured ORM
  • SQL Builder, Create/Delete/Find/Save/Count/Sum/Max/Avg/SetInc/SetDev with SQL Expr
  • Developer Not Friendly,Because I'm Rubbish

Contributing

You can commit PR to this repository

Quick start

package main

import "github.com/gobkc/sqlx"

func main() {
    db := sqlx.NewPg("postgres1", "password1", "localhost:5566", "testDb", "disable")
    err := db.Table("app").Where("id=?", 62).Update(&map[string]interface{}{"name":"123"})
    if err != nil {
        fmt.Println(err)
    }
}

Please refer to pgsql_test.go document for more example

License

© Gobkc, 2022~time.Now

Released under the Apache License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pg

type Pg struct {
	// contains filtered or unexported fields
}

func (*Pg) Conn

func (p *Pg) Conn() *sql.DB

func (*Pg) Table

func (p *Pg) Table(tableName string) Table

type PgQuery

type PgQuery struct {
	*Pg
}

func (*PgQuery) Avg

func (p *PgQuery) Avg(avg *int64) error

func (*PgQuery) Count

func (p *PgQuery) Count(count *int64) error

func (*PgQuery) Find

func (p *PgQuery) Find(dest interface{}) error

func (*PgQuery) Group

func (p *PgQuery) Group(group string) Query

func (*PgQuery) Limit

func (p *PgQuery) Limit(limit int64) Query

func (*PgQuery) Offset

func (p *PgQuery) Offset(offset int64) Query

func (*PgQuery) Sort

func (p *PgQuery) Sort(filed string, sortBy string) Query

func (*PgQuery) Sum

func (p *PgQuery) Sum(sum *int64) error

type PgTable

type PgTable struct {
	*Pg
}

func (*PgTable) Avg

func (p *PgTable) Avg(avg *int64) error

func (*PgTable) Count

func (p *PgTable) Count(count *int64) error

func (*PgTable) Delete

func (p *PgTable) Delete() error

func (*PgTable) Find

func (p *PgTable) Find(dest interface{}) error

func (*PgTable) Group

func (p *PgTable) Group(group string) Query

func (*PgTable) Limit

func (p *PgTable) Limit(limit int64) Query

func (*PgTable) Offset

func (p *PgTable) Offset(offset int64) Query

func (*PgTable) Save

func (p *PgTable) Save(dest interface{}) error

func (*PgTable) Select

func (p *PgTable) Select(fields string) Table

func (*PgTable) SetDec

func (p *PgTable) SetDec(field string) error

func (*PgTable) SetInc

func (p *PgTable) SetInc(field string) error

func (*PgTable) Sort

func (p *PgTable) Sort(filed string, sortBy string) Query

func (*PgTable) Sum

func (p *PgTable) Sum(sum *int64) error

func (*PgTable) Update

func (p *PgTable) Update(dest interface{}) error

func (*PgTable) Where

func (p *PgTable) Where(where string, argc ...interface{}) Table

func (*PgTable) WhereOr

func (p *PgTable) WhereOr(where string, argc ...interface{}) Table

type Query

type Query interface {
	Sort(filed string, sortBy string) Query
	Offset(offset int64) Query
	Limit(limit int64) Query
	Group(group string) Query
	Find(dest interface{}) error
	Count(count *int64) error
	Sum(sum *int64) error
	Avg(avg *int64) error
}

type SQL

type SQL interface {
	Conn() *sql.DB
	Table(tableName string) Table
	// contains filtered or unexported methods
}

func NewPg

func NewPg(user, pass, server, dbName, sslMode string) SQL

NewPg is used to create postgres connection dsn1: "postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full" dsn2: "port=5433 user=postgres password=123456 dbname=ficow sslmode=disable" dsn1 is used here

type Table

type Table interface {
	Select(fields string) Table
	Where(where string, argc ...interface{}) Table
	WhereOr(where string, argc ...interface{}) Table
	Sort(filed string, sortBy string) Query
	Offset(offset int64) Query
	Limit(limit int64) Query
	Group(group string) Query
	Find(dest interface{}) error
	Count(count *int64) error
	Sum(sum *int64) error
	Avg(avg *int64) error
	Update(dest interface{}) error
	Save(dest interface{}) error
	Delete() error
	SetInc(field string) error // feature:field value + 1
	SetDec(field string) error // feature:field value - 1
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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