dbm

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

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 11 Imported by: 0

README

模块

New().CreateTable()
New().AlterTable()


FromSql()
FromFile()
FromPath()
FromJson()

Migrate()
ToJson()
ToStruct()
ToSql()

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FIELD_PRESET = map[string]string{
	"id": "ID",
	"ip": "IP",
}

Functions

func Register

func Register(driver string, parser IDriver)

func ToCamelCase

func ToCamelCase(s string, isUcFirst ...bool) string

ToCamelCase converts a snake_case string to camelCase.

func ToSnakeCase

func ToSnakeCase(s string) string

ToSnakeCase converts a camelCase string to snake_case.

Types

type Charsets

type Charsets struct {
	Charset string
	Collate string
}

func (Charsets) ToStruct

func (c Charsets) ToStruct() string

type Column

type Column struct {
	Field        *Field
	Charsets     *Charsets
	IsUnsigned   bool
	IsNullable   bool
	IsAutoInc    bool
	KeyType      KeyType
	Comments     string
	DefaultValue string
}

func NewColumn

func NewColumn(col *Field) *Column

func (*Column) AutoIncrement

func (c *Column) AutoIncrement(b ...bool) *Column

func (*Column) Charset

func (c *Column) Charset(charset string) *Column

func (*Column) Collate

func (c *Column) Collate(collate string) *Column

func (*Column) Comment

func (c *Column) Comment(comment string) *Column

func (*Column) Default

func (c *Column) Default(value any) *Column

func (*Column) Enable

func (c *Column) Enable(db *Table)

func (*Column) Fulltext

func (c *Column) Fulltext() *Column

func (*Column) Index

func (c *Column) Index() *Column

func (*Column) Nullable

func (c *Column) Nullable(b ...bool) *Column

func (*Column) Primary

func (c *Column) Primary() *Column

func (*Column) ToStruct

func (c *Column) ToStruct() string

func (*Column) Unique

func (c *Column) Unique() *Column

func (*Column) Unsigned

func (c *Column) Unsigned() *Column

type DBM

type DBM struct {
	Tables []*Table
	// contains filtered or unexported fields
}

func FromSql

func FromSql(sqls string) *DBM

func NewDBM

func NewDBM(tabs ...*Table) *DBM

func (*DBM) Migrate

func (db *DBM) Migrate(driver, dsn string)

func (*DBM) SetPackageName

func (db *DBM) SetPackageName(pack string) *DBM

func (*DBM) ToJson

func (db *DBM) ToJson(driver string)

func (*DBM) ToSql

func (db *DBM) ToSql(driver string)

func (*DBM) ToStructToPath

func (db *DBM) ToStructToPath(filePath, driver string, tags ...*TagOption)

func (*DBM) ToStructToSingleFile

func (db *DBM) ToStructToSingleFile(filename, driver string, tags ...*TagOption)

func (*DBM) TryToStructToSingleFile

func (db *DBM) TryToStructToSingleFile(filename, driver string, tags ...*TagOption)

type DBSource

type DBSource struct {
	*sql.DB
}

func FromDB

func FromDB(db *sql.DB) (res *DBSource)

func FromDsn

func FromDsn(driver, dsn string) (res *DBSource)

func NewDBSource

func NewDBSource(db *sql.DB) *DBSource

func (*DBSource) All

func (db *DBSource) All() *DBM

func (*DBSource) Table

func (db *DBSource) Table(name string) *DBM

type Field

type Field struct {
	Name   string
	Type   string
	Length int
	Values []string
}

func Col

func Col(name string) *Field

func (*Field) Decimal

func (c *Field) Decimal(length, dot int) *Column

func (*Field) Int

func (c *Field) Int(length ...int) *Column

type IDriver

type IDriver interface {
	Go2Db(t string) string
	Db2Go(t string) string
	ToSql(tab *Table) string
}

func GetDriver

func GetDriver(driver string) IDriver

type IScheme

type IScheme interface {
	Enable(*Table)
}

type KeyType

type KeyType int8
const (
	KTPrimary KeyType = iota + 1
	KTIndex
	KTUnique
	KTFulltext
)

type Keys

type Keys struct {
	KeyType
	// contains filtered or unexported fields
}

func Index

func Index(kt KeyType, column string, columns ...string) Keys

func (Keys) Enable

func (c Keys) Enable(db *Table)

func (Keys) ToStruct

func (c Keys) ToStruct() string

type Mysql

type Mysql struct {
	*Table
}

func (*Mysql) Db2Go

func (*Mysql) Db2Go(t string) string

func (*Mysql) Go2Db

func (*Mysql) Go2Db(t string) string

func (*Mysql) ToSql

func (m *Mysql) ToSql(tab *Table) string

type Sql

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

func NewSql

func NewSql(sqls string) *Sql

func (*Sql) Parse

func (s *Sql) Parse() *Table

type Table

type Table struct {
	Charsets Charsets
	Name     string
	Comments string
	Engines  string
	Fields   []Column
	Index    []Keys
}

func FromFile

func FromFile(arg string) *Table

func FromJson

func FromJson(arg string) *Table

func NewTable

func NewTable(name string) *Table

func (*Table) Alter

func (db *Table) Alter(args ...IScheme) *DBM

func (*Table) Charset

func (db *Table) Charset(charset string) *Table

func (*Table) Collate

func (db *Table) Collate(collate string) *Table

func (*Table) Comment

func (db *Table) Comment(arg string) *Table

func (*Table) Create

func (db *Table) Create(args ...IScheme) *Table

func (*Table) Drop

func (db *Table) Drop(args ...IScheme) *DBM

func (*Table) Engine

func (db *Table) Engine(arg string) *Table

func (*Table) ToSql

func (db *Table) ToSql(driver string)

func (*Table) ToStruct

func (db *Table) ToStruct(driver string, tags ...*TagOption) string

type Tables

type Tables []Table

func FromPath

func FromPath(arg string) Tables

type TagOption

type TagOption struct {
	Name        string
	IsCamelcase bool
	IsSnakeCase bool
}

func Tag

func Tag(name string) *TagOption

func (*TagOption) CamelCase

func (tg *TagOption) CamelCase() *TagOption

func (*TagOption) SnakeCase

func (tg *TagOption) SnakeCase() *TagOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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