gosql

package module
v0.0.0-...-b39d511 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2018 License: MIT Imports: 11 Imported by: 0

README

gosql

golang sql builder tool, similar to mybatis.

follow the example of github.com/jmoiron/sqlx

go get github.com/xuruiray/gosql

example
  1. # represents string splicing
  2. $ represents prepare statement placeholder

test sql

select * from #tablename where driver_id = $driver_id #sort

test table info (MySQL 5.7.18)

--table info
CREATE TABLE `driver_info` (
  `id` int(20) NOT NULL AUTO_INCREMENT COMMENT '自增id',
  `driver_id` int(20) NOT NULL DEFAULT '0' COMMENT '司机ID',
  `name` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '0' COMMENT '司机姓名',
  `age` int(20) NOT NULL DEFAULT '0' COMMENT '司机年龄',
  PRIMARY KEY (`id`),
  KEY `inx_driver_id_age` (`driver_id`,`age`)
) ENGINE=InnoDB AUTO_INCREMENT=124 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

--row info
INSERT INTO `driver_info` (`id`, `driver_id`, `name`, `age`)
VALUES
	(123,456,X'7875727569',12),
	(124,457,X'7875727569',13),
	(125,458,X'7875727569',14),
	(126,459,X'7875727569',15);

demo


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(conn sqlbuilder.Database, sql string, params map[string]interface{}) (int64, error)

Execute 封装sql方法 执行sql语句 返回受影响的行数

func GetMySQLConn

func GetMySQLConn(username, password, url, dbname string) (sqlbuilder.Database, error)

GetMySQLConn 获取 mysql 连接

func GetPreparedStatement

func GetPreparedStatement(sql string, params map[string]interface{}) (string, []interface{}, error)

GetPreparedStatement 将传入的sql与params参数 整理成 prepare statement

func IsDuplicatedError

func IsDuplicatedError(err error) bool

IsDuplicatedMySQLError 判断是否为重复插入错误

func QueryList

func QueryList(conn sqlbuilder.Database, sql string, params map[string]interface{}, res interface{}) error

GetList 封装查询方法 查询多行数据 结果封入res中

func QueryOne

func QueryOne(conn sqlbuilder.Database, sqlStr string, params map[string]interface{}, res interface{}) error

GetOne 封装查询方法 查询单行数据 结果封入res中

Types

This section is empty.

Jump to

Keyboard shortcuts

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