gsql

package module
v0.0.0-...-64dc28f Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

gsql

介绍

使用go语言编写的简易SQL模块,基于github.com/go-sql-driver/mysqldatabase/sql项目

安装

go get -u gitee.com/liumou_site/gsql

使用说明

package main

import (
	"gitee.com/liumou_site/gsql"
	"gitee.com/liumou_site/logger"
)

func main()  {
    c := gsql.New("passwd")
	c.initConnect()
	c.Commit("UPDATE `te`.`t` SET `name`='2' WHERE  `id`=1;")
	if err != nil {
		logger.Error(err.Error())
	} else {
		logger.Info("ok")
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SqlCmd

type SqlCmd struct {
	Set     *SqlStruct // 连接实例
	Connect string     // 数据库连接参数
	DB      *sql.DB    // 数据库连接实例
}

func New

func New(passwd string) *SqlCmd

New 新建连接

func (*SqlCmd) Commit

func (api *SqlCmd) Commit(cmd string) (err error)

func (*SqlCmd) CommitList

func (api *SqlCmd) CommitList(cmd []string) (err error)

func (*SqlCmd) Query

func (api *SqlCmd) Query(cmd string) (err error)

type SqlStruct

type SqlStruct struct {
	Host     string        // 服务器地址,默认: 127.0.0.1
	User     string        // 用户名,默认: root
	Passwd   string        // 登录密码,必须设置
	Port     int           // 端口,默认: 3306
	Db       string        // 数据库名称,默认: mysql
	Table    string        // 表名称,默认: user
	TimeOut  time.Duration // 连接超时时间(单位: 秒),默认: 10
	ReadTime time.Duration // 读取超时(单位: 秒),默认: 20
}

Jump to

Keyboard shortcuts

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