schema

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetTagName

func SetTagName(tag string)

Set custom struct tag for database types. default is "sql"

Types

type Field

type Field struct {
	Name         string
	ColumnName   string
	DType        string
	Nullable     bool
	DefaultValue string
	Table        *Table
}

Represents a database field.

type ForeignKey

type ForeignKey struct {
	Name                string
	ReferencedTable     string
	ReferencedFieldName string
}

Represents a foreign key

type Table

type Table struct {
	Model       any
	TableName   string
	PrimaryKey  string
	Fields      []Field
	ForeignKeys []ForeignKey
}

Represents

type TableMap

type TableMap map[string]Table

func GenerateSchema

func GenerateSchema(models []any) (schemas []string, tableMap TableMap, table_names []string)

Parse the models(structs) and generate sql statements to create the tables. Returns the table create statements and a list of table names. Schema is sorted(as best as possible) to avoid errors during migrations.

Jump to

Keyboard shortcuts

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