sqlsrv

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

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

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

README

sqlsrv

sql tool function

Documentation

Overview

odbc查询工具函数 By woylin 2016.6.14

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangeDb

func ChangeDb(s ...string) error

ChangeDb 更改配置

func CheckBool

func CheckBool(sql string, cond ...interface{}) bool

CheckBool 检查是否存在

func Exec

func Exec(query string, cond ...interface{}) error

Exec 执行SQL,update/insert/delete

func Fetch

func Fetch(query string, cond ...interface{}) *interface{}

Fetch 返回单值

func FetchAll

func FetchAll(query string, cond ...interface{}) *[]interface{}

FetchAll 返回所有行

func FetchAllJson

func FetchAllJson(sql string, cond ...interface{}) string

FetchAllJson 返回所有行的Json

func FetchAllRowsPtr

func FetchAllRowsPtr(query string, struc interface{}, cond ...interface{}) *[]interface{}

FetchAllRowsPtr 通用查询

func FetchMenuTree

func FetchMenuTree(query string, cond ...interface{}) *treeNode

FetchMenuTree ES目录树

func FetchOne

func FetchOne(query string, cond ...interface{}) *map[string]interface{}

FetchOne 返回单行

func FetchOnePtr

func FetchOnePtr(query string, struc interface{}, cond ...interface{}) *interface{}

FetchOnePtr 通用查询单条

func FetchOneString

func FetchOneString(query string, cond ...interface{}) map[string]string

FetchOneString 返回单行文本

func NumRows

func NumRows(query string, cond ...interface{}) int

NumRows 返回行数

func SetConf

func SetConf(confPath string)

SetConf 配置DB参数

func SqlChk

func SqlChk(s string) string

SqlChk 防sql注入

Types

type Db

type Db struct {
	*sql.DB
}

Db 数据库连接

func NewDb

func NewDb(conf *DbConf) (d *Db, err error)

func (*Db) CheckBool

func (d *Db) CheckBool(sql string, cond ...interface{}) bool

CheckBool 检查是否存在

func (*Db) Exec

func (d *Db) Exec(query string, cond ...interface{}) error

Exec 执行SQL,update/insert/delete

func (*Db) Fetch

func (d *Db) Fetch(query string, cond ...interface{}) (interface{}, error)

Fetch 返回单值

func (*Db) FetchAll

func (d *Db) FetchAll(query string, cond ...interface{}) (*[]interface{}, error)

FetchAll 返回所有行

func (*Db) FetchAllRowsPtr

func (d *Db) FetchAllRowsPtr(query string, struc interface{}, cond ...interface{}) *[]interface{}

FetchAllRowsPtr 通用查询

func (*Db) FetchOnePtr

func (d *Db) FetchOnePtr(query string, struc interface{}, cond ...interface{}) *interface{}

FetchOnePtr 通用查询单条

func (*Db) NumRows

func (d *Db) NumRows(query string, cond ...interface{}) int

NumRows 返回行数

type DbConf

type DbConf struct {
	UserId string
	Pwd    string
	Server string
	DbName string
}

配置文件位于conf/db.json,类似下列这样:

{
	"UserId" :"sa",
	"Pwd"	 :"password",
	"Server" :"serverIP",
	"DbName" :"DBname"
}

Jump to

Keyboard shortcuts

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