database

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package database ...

Copyright © 2019 hajime-terasawa <terako.studio@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package database ...

Copyright © 2019 hajime-terasawa <terako.studio@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var IncrementableDataType = []interface{}{
	"tinyint",
	"smallint",
	"mediumint",
	"int",
	"bigint",
}

IncrementableDataType accepts increment options

View Source
var MaxConnections int

MaxConnections holds max_connections var for memory use control

View Source
var OrderRequiredDataTypes = []interface{}{
	"tinyint",
	"smallint",
	"mediumint",
	"int",
	"bigint",
	"bit",
	"blob",
	"text",
	"year",
	"char",
	"varchar",
	"binary",
	"varbinary",
}

OrderRequiredDataTypes require DataType(Order) like sql

View Source
var PrecisionRequiredDataTypes = []interface{}{
	"decimal",
	"float",
	"real",
	"double",
}

PrecisionRequiredDataTypes require DataType(Order, Precision) like sql

View Source
var ProhibitDefaultDataTypes = []interface{}{
	"tinyblob",
	"tinytext",
	"blob",
	"text",
	"mediumblob",
	"mediumtext",
	"longblob",
	"longtext",
}

ProhibitDefaultDataTypes must allow null value

View Source
var UnsignedableDataType = []interface{}{
	"tinyint",
	"smallint",
	"mediumint",
	"int",
	"bigint",
	"decimal",
	"float",
	"real",
	"double",
}

UnsignedableDataType accepts unsigned options

View Source
var Verbose bool

Verbose displays sql from cobra

Functions

func SetupMySQLDB

func SetupMySQLDB(cfg *config.Database) error

SetupMySQLDB find_or_create database w/ given database name, then connect it

Types

type DBClient

type DBClient interface {
	CreateTable(cfg *config.Table) error
	DropTable(cfg *config.Table) error
	Populate(cfg *config.Table) error
}

DBClient is an interface for DB Querying

func BuildClient

func BuildClient(cfg *config.Database) (DBClient, error)

BuildClient builds DBClient for abstraction

func DB

func DB() DBClient

DB provides instance of DB client

type MySQLClient

type MySQLClient struct {
	*sqlx.DB
}

MySQLClient is an implementation of DBClient for MySQL

func BuildMySQLClient

func BuildMySQLClient(cfg *config.Database) (*MySQLClient, error)

BuildMySQLClient returns MySQLClient

func (*MySQLClient) BuildCreateTableStmt

func (db *MySQLClient) BuildCreateTableStmt(cfg *config.Table) string

BuildCreateTableStmt generate create_table_stmt sql for MySQL

func (*MySQLClient) BuildDefaultDesc

func (db *MySQLClient) BuildDefaultDesc(cfg *config.Column) string

BuildDefaultDesc generate a default desc part of sql for MySQL

func (*MySQLClient) BuildDropTableStmt

func (db *MySQLClient) BuildDropTableStmt(cfg *config.Table) string

BuildDropTableStmt generate drop_table_stmt sql for MySQL

func (*MySQLClient) BuildIndexDesc

func (db *MySQLClient) BuildIndexDesc(cfg *config.Index) string

BuildIndexDesc generate an index desc part of sql for MySQL

func (*MySQLClient) BuildInsertStmt

func (db *MySQLClient) BuildInsertStmt(cfg *config.Table, values []string) string

BuildInsertStmt generate insert_stmt sql for MySQL

func (*MySQLClient) CreateTable

func (db *MySQLClient) CreateTable(cfg *config.Table) error

CreateTable does CreateTable statement for MySQL

func (*MySQLClient) DropTable

func (db *MySQLClient) DropTable(cfg *config.Table) error

DropTable does DropTable statement for MySQL

func (*MySQLClient) Populate

func (db *MySQLClient) Populate(cfg *config.Table) error

Populate does Insert statement for MySQL

Jump to

Keyboard shortcuts

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