trenovaorm

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

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

Go to latest
Published: Jun 27, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConstraintUnqiue     = Constraint("UNIQUE")
	ConstraintNotNull    = Constraint("NOT NULL")
	ConstraintCheck      = Constraint("CHECK")
	ConstraintPrimaryKey = Constraint("PRIMARY KEY")
	ConstraintDefault    = Constraint("DEFAULT")
)
View Source
const (
	CurrentTimestamp = PSQLFunction("current_timestamp")
	UUIDGenerateV4   = PSQLFunction("uuid_generate_v4()")
)

Predefined PostgreSQL functions.

Variables

This section is empty.

Functions

This section is empty.

Types

type Annotation

type Annotation struct {
	OnDelete OnDeleteOption
	OnUpdate OnUpdateOption
}

Annotation represents the annotations for foreign key relationships.

func (Annotation) String

func (a Annotation) String() string

type BaseField

type BaseField struct {
	ColumnName  string
	Nullable    bool
	Unique      bool
	Index       bool
	Comment     string
	CustomType  string
	Constraints []string
	StructTag   string
}

BaseField provides common properties for all fields.

func (*BaseField) Name

func (f *BaseField) Name() string

type BaseMixin

type BaseMixin struct{}

BaseMixin struct to be embedded in mixins.

func (BaseMixin) Fields

func (BaseMixin) Fields() []Field

Fields returns an empty slice for base mixin.

type BaseModel

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

BaseModel provides common fields and methods for all models.

func (*BaseModel) Fields

func (b *BaseModel) Fields() []Field

Fields returns the fields defined by the model, including mixin fields.

func (*BaseModel) Indexes

func (b *BaseModel) Indexes() []Index

Indexes returns an empty slice for base model.

func (*BaseModel) Mixins

func (b *BaseModel) Mixins() []Mixin

Mixins returns the mixins for the model. This method should be overridden by concrete models if they have mixins.

func (*BaseModel) SetTableName

func (b *BaseModel) SetTableName(name string)

SetTableName allows overriding the default table name.

func (*BaseModel) TableName

func (b *BaseModel) TableName() string

TableName returns the table name for the model.

type BooleanField

type BooleanField struct {
	ColumnName  string
	Nullable    bool
	Unique      bool
	Default     bool
	Index       bool
	Comment     string
	CustomType  string
	Constraints []string
	StructTag   string
}

BooleanField represents a boolean field in the database.

func (*BooleanField) CommentSQL

func (f *BooleanField) CommentSQL(tableName string) string

CommentSQL generates the SQL statement for adding a comment to the BooleanField.

func (*BooleanField) Definition

func (f *BooleanField) Definition() string

Definition generates the SQL definition for the BooleanField.

func (*BooleanField) GoType

func (f *BooleanField) GoType() string

GoType returns the Go type for the BooleanField.

func (*BooleanField) IndexSQL

func (f *BooleanField) IndexSQL(tableName string) string

IndexSQL generates the SQL statement for creating an index if Index is true.

func (*BooleanField) Name

func (f *BooleanField) Name() string

Name returns the column name for the BooleanField.

func (*BooleanField) Validate

func (f *BooleanField) Validate() error

Validate checks if the field's configuration is valid.

type Btree

type Btree struct {
	Column string
}

Btree defines a BTREE index in PostgreSQL.

func (Btree) ColumnName

func (b Btree) ColumnName() string

func (Btree) Expression

func (b Btree) Expression() string

type CharField

type CharField struct {
	ColumnName  string
	MaxLength   int
	Nullable    bool
	Blank       bool
	Unique      bool
	Default     string
	Index       bool
	Comment     string
	CustomType  string
	Constraints []string
	StructTag   string
}

CharField represents a string field in the database.

func (*CharField) CommentSQL

func (f *CharField) CommentSQL(tableName string) string

CommentSQL generates the SQL statement for adding a comment to the CharField.

func (*CharField) Definition

func (f *CharField) Definition() string

Definition generates the SQL definition for the CharField.

func (*CharField) GoType

func (f *CharField) GoType() string

GoType returns the Go type for the CharField.

func (*CharField) IndexSQL

func (f *CharField) IndexSQL(tableName string) string

IndexSQL generates the SQL statement for creating an index if Index is true.

func (*CharField) Name

func (f *CharField) Name() string

Name returns the column name for the CharField.

func (*CharField) Validate

func (f *CharField) Validate() error

Validate checks if the field's configuration is valid.

type Concat

type Concat struct {
	Columns []string
}

Concat defines a CONCAT expression in PostgreSQL for string concatenation.

func (Concat) ColumnName

func (c Concat) ColumnName() string

func (Concat) Expression

func (c Concat) Expression() string

type Constraint

type Constraint string

func (Constraint) String

func (c Constraint) String() string

type DateField

type DateField struct {
	ColumnName  string
	Nullable    bool
	Unique      bool
	Default     PSQLFunction
	Index       bool
	Comment     string
	CustomType  string
	Constraints []string
	StructTag   string
}

DateField represents a date field in the database.

func (*DateField) CommentSQL

func (f *DateField) CommentSQL(tableName string) string

CommentSQL generates the SQL statement for adding a comment to the DateField.

func (*DateField) Definition

func (f *DateField) Definition() string

Definition generates the SQL definition for the DateField.

func (*DateField) GoType

func (f *DateField) GoType() string

GoType returns the Go type for the DateField.

func (*DateField) IndexSQL

func (f *DateField) IndexSQL(tableName string) string

IndexSQL generates the SQL statement for creating an index if Index is true.

func (*DateField) Name

func (f *DateField) Name() string

Name returns the column name for the DateField.

func (*DateField) Validate

func (f *DateField) Validate() error

Validate checks if the field's configuration is valid.

type Expression

type Expression interface {
	Expression() string
	ColumnName() string // To be used for naming the index
}

Expression defines a PostgreSQL expression.

type Field

type Field interface {
	Definition() string
	Name() string
	Validate() error
	CommentSQL(tableName string) string
	GoType() string
}

Field defines a general database field interface.

type ForeignKeyField

type ForeignKeyField struct {
	ColumnName     string
	ReferenceTable string
	ReferenceField string
	Annotations    Annotation
	Nullable       bool
	Unique         bool
	Default        string
	Index          bool
	Comment        string
	CustomType     string
	Constraints    []string
	StructTag      string
	ReferencedType string // The Go type of the referenced field
}

ForeignKeyField represents a foreign key field in the database.

func (*ForeignKeyField) CommentSQL

func (f *ForeignKeyField) CommentSQL(tableName string) string

CommentSQL generates the SQL statement for adding a comment to the ForeignKeyField.

func (*ForeignKeyField) Definition

func (f *ForeignKeyField) Definition() string

Definition generates the SQL definition for the ForeignKeyField.

func (*ForeignKeyField) ForeignKeyConstraint

func (f *ForeignKeyField) ForeignKeyConstraint(tableName string) string

ForeignKeyConstraint generates the SQL for the foreign key constraint.

func (*ForeignKeyField) GoType

func (f *ForeignKeyField) GoType() string

GoType returns the Go type for the ForeignKeyField.

func (*ForeignKeyField) IndexSQL

func (f *ForeignKeyField) IndexSQL(tableName string) string

IndexSQL generates the SQL statement for creating an index if Index is true.

func (*ForeignKeyField) Name

func (f *ForeignKeyField) Name() string

Name returns the column name for the ForeignKeyField.

func (*ForeignKeyField) Validate

func (f *ForeignKeyField) Validate() error

Validate checks if the field's configuration is valid.

type Gin

type Gin struct {
	Column string
}

Gin defines a GIN index in PostgreSQL.

func (Gin) ColumnName

func (g Gin) ColumnName() string

func (Gin) Expression

func (g Gin) Expression() string

type Gist

type Gist struct {
	Column string
}

Gist defines a GIST index in PostgreSQL.

func (Gist) ColumnName

func (g Gist) ColumnName() string

func (Gist) Expression

func (g Gist) Expression() string

type Hash

type Hash struct {
	Column string
}

Hash defines a HASH index in PostgreSQL.

func (Hash) ColumnName

func (h Hash) ColumnName() string

func (Hash) Expression

func (h Hash) Expression() string

type Index

type Index struct {
	Name        string       // Index name
	Columns     []string     // Simple column names
	Expressions []Expression // Custom SQL expressions as Expression interface
	Unique      bool         // Whether the index is unique
}

Index defines the structure for database indices, supporting both simple and complex cases.

func (*Index) SQL

func (idx *Index) SQL(tableName string) (string, error)

SQL generates the SQL statement for creating the index on a given table.

func (*Index) Validate

func (idx *Index) Validate() error

Validate checks the integrity of the Index struct.

type IntegerField

type IntegerField struct {
	ColumnName  string
	Nullable    bool
	Unique      bool
	Default     int
	Index       bool
	Comment     string
	CustomType  string
	Constraints []string
	StructTag   string
}

IntegerField represents an integer field in the database.

func (*IntegerField) CommentSQL

func (f *IntegerField) CommentSQL(tableName string) string

CommentSQL generates the SQL statement for adding a comment to the IntegerField.

func (*IntegerField) Definition

func (f *IntegerField) Definition() string

Definition generates the SQL definition for the IntegerField.

func (*IntegerField) GoType

func (f *IntegerField) GoType() string

GoType returns the Go type for the IntegerField.

func (*IntegerField) IndexSQL

func (f *IntegerField) IndexSQL(tableName string) string

IndexSQL generates the SQL statement for creating an index if Index is true.

func (*IntegerField) Name

func (f *IntegerField) Name() string

Name returns the column name for the IntegerField.

func (*IntegerField) Validate

func (f *IntegerField) Validate() error

Validate checks if the field's configuration is valid.

type JSONField

type JSONField struct {
	ColumnName  string
	Nullable    bool
	Unique      bool
	Default     string
	Index       bool
	Comment     string
	CustomType  string
	Constraints []string
	StructTag   string
}

JSONField represents a JSON field in the database.

func (*JSONField) CommentSQL

func (f *JSONField) CommentSQL(tableName string) string

CommentSQL generates the SQL statement for adding a comment to the JSONField.

func (*JSONField) Definition

func (f *JSONField) Definition() string

Definition generates the SQL definition for the JSONField.

func (*JSONField) GoType

func (f *JSONField) GoType() string

GoType returns the Go type for the JSONField.

func (*JSONField) IndexSQL

func (f *JSONField) IndexSQL(tableName string) string

IndexSQL generates the SQL statement for creating an index if Index or Unique is true.

func (*JSONField) Name

func (f *JSONField) Name() string

Name returns the column name for the JSONField.

func (*JSONField) Validate

func (f *JSONField) Validate() error

Validate checks if the field's configuration is valid.

type Lower

type Lower struct {
	Column string
}

Lower defines the LOWER expression in PostgreSQL.

func (Lower) ColumnName

func (l Lower) ColumnName() string

func (Lower) Expression

func (l Lower) Expression() string

type Mixin

type Mixin interface {
	Fields() []Field
}

Mixin interface for defining mixin fields.

type Model

type Model interface {
	Fields() []Field
	Indexes() []Index
	TableName() string
	Mixins() []Mixin
}

Model interface for defining entity models.

type NumericField

type NumericField struct {
	ColumnName  string
	Precision   int
	Scale       int
	Nullable    bool
	Unique      bool
	Default     float64
	Index       bool
	Comment     string
	CustomType  string
	Constraints []string
	StructTag   string
}

NumericField represents a numeric field in the database.

func (*NumericField) CommentSQL

func (f *NumericField) CommentSQL(tableName string) string

CommentSQL generates the SQL statement for adding a comment to the NumericField.

func (*NumericField) Definition

func (f *NumericField) Definition() string

Definition generates the SQL definition for the NumericField.

func (*NumericField) GoType

func (f *NumericField) GoType() string

GoType returns the Go type for the NumericField.

func (*NumericField) IndexSQL

func (f *NumericField) IndexSQL(tableName string) string

IndexSQL generates the SQL statement for creating an index if Index is true.

func (*NumericField) Name

func (f *NumericField) Name() string

Name returns the column name for the NumericField.

func (*NumericField) Validate

func (f *NumericField) Validate() error

Validate checks if the field's configuration is valid.

type OnDeleteOption

type OnDeleteOption string

OnDeleteOption defines the possible options for the ON DELETE behavior.

const (
	OnDeleteCascade  OnDeleteOption = "CASCADE"
	OnDeleteSetNull  OnDeleteOption = "SET NULL"
	OnDeleteRestrict OnDeleteOption = "RESTRICT"
	OnDeleteNoAction OnDeleteOption = "NO ACTION"
)

type OnUpdateOption

type OnUpdateOption string

OnUpdateOption defines the possible options for the ON UPDATE behavior.

const (
	OnUpdateCascade  OnUpdateOption = "CASCADE"
	OnUpdateSetNull  OnUpdateOption = "SET NULL"
	OnUpdateRestrict OnUpdateOption = "RESTRICT"
	OnUpdateNoAction OnUpdateOption = "NO ACTION"
)

type PSQLFunction

type PSQLFunction string

Function represents a PostgreSQL function.

func (PSQLFunction) String

func (f PSQLFunction) String() string

Default returns the function as a default value for a field.

type PositiveIntegerField

type PositiveIntegerField struct {
	ColumnName  string
	Nullable    bool
	Unique      bool
	Default     int
	Index       bool
	Comment     string
	CustomType  string
	Constraints []string
	StructTag   string
}

PositiveIntegerField represents a positive integer field in the database.

func (*PositiveIntegerField) CommentSQL

func (f *PositiveIntegerField) CommentSQL(tableName string) string

CommentSQL generates the SQL statement for adding a comment to the PositiveIntegerField.

func (*PositiveIntegerField) Definition

func (f *PositiveIntegerField) Definition() string

Definition generates the SQL definition for the PositiveIntegerField.

func (*PositiveIntegerField) GoType

func (f *PositiveIntegerField) GoType() string

GoType returns the Go type for the PositiveIntegerField.

func (*PositiveIntegerField) IndexSQL

func (f *PositiveIntegerField) IndexSQL(tableName string) string

IndexSQL generates the SQL statement for creating an index if Index or Unique is true.

func (*PositiveIntegerField) Name

func (f *PositiveIntegerField) Name() string

Name returns the column name for the PositiveIntegerField.

func (*PositiveIntegerField) Validate

func (f *PositiveIntegerField) Validate() error

Validate checks if the field's configuration is valid.

type TextField

type TextField struct {
	ColumnName  string
	Nullable    bool
	Blank       bool
	Unique      bool
	Default     string
	Index       bool
	Comment     string
	CustomType  string
	Constraints []string
	StructTag   string
}

TextField represents a text field in the database.

func (*TextField) CommentSQL

func (f *TextField) CommentSQL(tableName string) string

CommentSQL generates the SQL statement for adding a comment to the TextField.

func (*TextField) Definition

func (f *TextField) Definition() string

Definition generates the SQL definition for the TextField.

func (*TextField) GoType

func (f *TextField) GoType() string

GoType returns the Go type for the TextField.

func (*TextField) IndexSQL

func (f *TextField) IndexSQL(tableName string) string

IndexSQL generates the SQL statement for creating an index if Index is true.

func (*TextField) Name

func (f *TextField) Name() string

Name returns the column name for the TextField.

func (*TextField) Validate

func (f *TextField) Validate() error

Validate checks if the field's configuration is valid.

type TimeField

type TimeField struct {
	ColumnName  string
	Nullable    bool
	Unique      bool
	Default     PSQLFunction
	Index       bool
	Comment     string
	CustomType  string
	Constraints []string
	StructTag   string
}

TimeField represents a time field in the database.

func (*TimeField) CommentSQL

func (f *TimeField) CommentSQL(tableName string) string

CommentSQL generates the SQL statement for adding a comment to the TimeField.

func (*TimeField) Definition

func (f *TimeField) Definition() string

Definition generates the SQL definition for the TimeField.

func (*TimeField) GoType

func (f *TimeField) GoType() string

GoType returns the Go type for the TimeField.

func (*TimeField) IndexSQL

func (f *TimeField) IndexSQL(tableName string) string

IndexSQL generates the SQL statement for creating an index if Index is true.

func (*TimeField) Name

func (f *TimeField) Name() string

Name returns the column name for the TimeField.

func (*TimeField) Validate

func (f *TimeField) Validate() error

Validate checks if the field's configuration is valid.

type TimeOnly

type TimeOnly struct {
	Time time.Time
}

TimeOnly wraps a time.Time to provide custom scanning and formatting.

func (TimeOnly) MarshalJSON

func (t TimeOnly) MarshalJSON() ([]byte, error)

MarshalJSON converts the TimeOnly object to JSON.

func (*TimeOnly) Scan

func (t *TimeOnly) Scan(value any) error

Scan implements the Scanner interface.

func (*TimeOnly) UnmarshalJSON

func (t *TimeOnly) UnmarshalJSON(data []byte) error

UnmarshalJSON converts JSON data to a TimeOnly object.

func (TimeOnly) Value

func (t TimeOnly) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type TimestampedMixin

type TimestampedMixin struct {
	BaseMixin
}

TimestampedMixin provides common fields for tracking creation and update times.

func (TimestampedMixin) Fields

func (t TimestampedMixin) Fields() []Field

Fields returns the common timestamp fields.

type ToTSVector

type ToTSVector struct {
	Config string
	Column string
}

ToTsVector defines a Tsvector expression for full-text search in PostgreSQL.

func (ToTSVector) ColumnName

func (t ToTSVector) ColumnName() string

func (ToTSVector) Expression

func (t ToTSVector) Expression() string

type UUIDField

type UUIDField struct {
	ColumnName  string
	Nullable    bool
	Blank       bool
	Unique      bool
	Default     PSQLFunction
	Index       bool
	Comment     string
	CustomType  string
	Constraints []string
	PrimaryKey  bool
	StructTag   string
}

UUIDField represents a UUID field in the database.

func (*UUIDField) CommentSQL

func (f *UUIDField) CommentSQL(tableName string) string

func (*UUIDField) Definition

func (f *UUIDField) Definition() string

func (*UUIDField) GoType

func (f *UUIDField) GoType() string

func (*UUIDField) IndexSQL

func (f *UUIDField) IndexSQL(tableName string) string

IndexSQL generates the SQL statement for creating an index if Index is true.

func (*UUIDField) Name

func (f *UUIDField) Name() string

func (*UUIDField) Validate

func (f *UUIDField) Validate() error

type Upper

type Upper struct {
	Column string
}

Upper defines the UPPER expression in PostgreSQL.

func (Upper) ColumnName

func (u Upper) ColumnName() string

func (Upper) Expression

func (u Upper) Expression() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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