bgbatis

package module
v0.0.2-beta Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: Apache-2.0 Imports: 13 Imported by: 1

README

BGBATIS

Introduction

A sample db tools with stored sqls in xml files

Install

import "gitee.com/billcoding/bgbatis"

Usage

  • Go Code
import (
	"database/sql"
	"fmt"
	"gitee.com/billcoding/bgbatis"
)

var dsn = "root:123456@tcp(localhost:3306)/test"

func main() {
	batis := bgbatis.Batis().Dsn(dsn).Init()
	err := batis.Mapper("test").Select("selectTest").Exec(func(rows *sql.Rows) {
		if rows.Next() {
			var t string
			rows.Scan(&t)
			fmt.Printf("time is %v", t)
		}
	})
	fmt.Println(err)
}

Demo

Default Config

  • Default dialect is mysql
  • Default mapper file path is ./mapper
  • Default show sql is false

Tx Supports

  • Begin tx using batis.Begin()
  • Commit tx using batis.Commit()
  • Rollback tx using batis.Rollback()

NamedParam Supports

  • Mapper file node
insert into table(name1, name2) values ('@name1@', '@name2@')
  • Code set
batis.Mapper(BINDING).Update(ID).ExecWithParams(batis.NamedParam("name1", "zhangsan"), batis.NamedParam("name2", "lisi"))

Env Supports

  • Dialect using variable BGBATIS_DIALECT
  • Mapper file paths using variable BGBATIS_MAPPER_PATH
  • Show sql using variable BGBATIS_SHOW_SQL
  • Dsn using variable BGBATIS_DSN

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Batis

func Batis() *batis

New batis

Types

type Dialect

type Dialect interface {
	// contains filtered or unexported methods
}

Define dialect struct

type DialectType

type DialectType string
const (
	DialectMysql DialectType = "mysql"
)

type NamedParam

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

Define namedParam struct

func NewNamedParam

func NewNamedParam(name string, val interface{}) *NamedParam

New namedParam

Jump to

Keyboard shortcuts

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