gsql

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: MIT Imports: 7 Imported by: 0

README

gsql execute sql script

Automatically generate a specified number of databases and tables according to SQL file content

Database and Table Sharding SQL file content

Example

import (
    "github.com/sanxia/gsql"
)

sqlBuilder := gsql.NewSqlBuilder()
sqlBuilder.Configs = gsql.DatabaseConfigList{
    gsql.DatabaseConfig{
        Name:  "sanxia_user",
        Count: 2,
        Source: gsql.DatabaseSource{
            Username: "sanxia",
            Password: "sanxia",
            Host:     "127.0.0.1:3306",
        },
        TableConfigs: gsql.TableConfigList{
            gsql.TableConfig{
                Name:  "sx_user_account",
                Count: 2,
                IsNew: true,
            },
            gsql.TableConfig{
                Name:  "sx_user_profile",
                Count: 2,
                IsNew: true,
            },
        },
        IsNew: true,
    },
}

sqlBuilder.Build()

Sql File Path

main.go

sql

-- databasename

-- tablename.sql

Builder Result

Create Database:

1. sanxia_user_00000
-----
Create Table:
-----
1.1 sx_user_account_00000
1.2 sx_user_account_00001
1.3 sx_user_profile_00000
1.4 sx_user_profile_00001

2. sanxia_user_00001
-----
Create Table:
-----
2.1 sx_user_account_00000
2.2 sx_user_account_00001
2.3 sx_user_profile_00000
2.4 sx_user_profile_00001

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSqlBuilder

func NewSqlBuilder() *sqlBuilder

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * 实例化SqlBuilder * args: sql base path * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Types

type Database

type Database struct {
	Source DatabaseSource
	Name   string //数据库名称
	Sql    string //sql语句

	IsNew     bool //是否重新创建
	IsBuilded bool //是否已生成过
	// contains filtered or unexported fields
}

func (*Database) Close

func (s *Database) Close() error

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * 关闭数据库连接 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*Database) Exec

func (s *Database) Exec(sql string, args ...string) (sql.Result, error)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * 运行Sql语句 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*Database) Open

func (s *Database) Open(args ...string) error

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * 打开数据库连接 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*Database) Query

func (s *Database) Query(sql string, args ...string) ([]map[string]interface{}, error)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * Sql集合查询 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

type DatabaseConfig

type DatabaseConfig struct {
	Name         string
	Count        int
	TableConfigs TableConfigList
	Source       DatabaseSource
	IsNew        bool //是否重建库
	IsSharding   bool //是否分片
	IsBuilded    bool //是否已生成过
}

type DatabaseConfigList

type DatabaseConfigList []DatabaseConfig

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * 数据库配置域结构 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

type DatabaseList

type DatabaseList []*Database

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * 数据库域结构 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

type DatabaseSource

type DatabaseSource struct {
	Username string
	Password string
	Host     string
}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * 数据源配置域结构 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

type Table

type Table struct {
	Name string //表名称
	Sql  string //sql语句

	Database  *Database
	IsNew     bool //是否重新创建
	IsBuilded bool //是否已生成过
	// contains filtered or unexported fields
}

type TableConfig

type TableConfig struct {
	Name       string
	Count      int
	IsNew      bool //是否重建表
	IsSharding bool //是否分片
	IsBuilded  bool //是否已生成过
}

type TableConfigList

type TableConfigList []TableConfig

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * 数据表配置域结构 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

type TableList

type TableList []*Table

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * 数据表域结构 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Jump to

Keyboard shortcuts

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