Documentation ¶
Index ¶
- Constants
- type Annotation
- type BaseField
- type BaseMixin
- type BaseModel
- type BooleanField
- type Btree
- type CharField
- type Concat
- type Constraint
- type DateField
- type Expression
- type Field
- type ForeignKeyField
- func (f *ForeignKeyField) CommentSQL(tableName string) string
- func (f *ForeignKeyField) Definition() string
- func (f *ForeignKeyField) ForeignKeyConstraint(tableName string) string
- func (f *ForeignKeyField) GoType() string
- func (f *ForeignKeyField) IndexSQL(tableName string) string
- func (f *ForeignKeyField) Name() string
- func (f *ForeignKeyField) Validate() error
- type Gin
- type Gist
- type Hash
- type Index
- type IntegerField
- type JSONField
- type Lower
- type Mixin
- type Model
- type NumericField
- type OnDeleteOption
- type OnUpdateOption
- type PSQLFunction
- type PositiveIntegerField
- func (f *PositiveIntegerField) CommentSQL(tableName string) string
- func (f *PositiveIntegerField) Definition() string
- func (f *PositiveIntegerField) GoType() string
- func (f *PositiveIntegerField) IndexSQL(tableName string) string
- func (f *PositiveIntegerField) Name() string
- func (f *PositiveIntegerField) Validate() error
- type TextField
- type TimeField
- type TimeOnly
- type TimestampedMixin
- type ToTSVector
- type UUIDField
- type Upper
Constants ¶
const ( ConstraintUnqiue = Constraint("UNIQUE") ConstraintNotNull = Constraint("NOT NULL") ConstraintCheck = Constraint("CHECK") ConstraintPrimaryKey = Constraint("PRIMARY KEY") ConstraintDefault = Constraint("DEFAULT") )
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.
type BaseModel ¶
type BaseModel struct {
// contains filtered or unexported fields
}
BaseModel provides common fields and methods for all models.
func (*BaseModel) Mixins ¶
Mixins returns the mixins for the model. This method should be overridden by concrete models if they have mixins.
func (*BaseModel) SetTableName ¶
SetTableName allows overriding the default table name.
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 (Btree) Expression ¶
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 ¶
CommentSQL generates the SQL statement for adding a comment to the CharField.
func (*CharField) Definition ¶
Definition generates the SQL definition for the CharField.
func (*CharField) IndexSQL ¶
IndexSQL generates the SQL statement for creating an index if Index is true.
type Concat ¶
type Concat struct {
Columns []string
}
Concat defines a CONCAT expression in PostgreSQL for string concatenation.
func (Concat) ColumnName ¶
func (Concat) Expression ¶
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 ¶
CommentSQL generates the SQL statement for adding a comment to the DateField.
func (*DateField) Definition ¶
Definition generates the SQL definition for the DateField.
func (*DateField) IndexSQL ¶
IndexSQL generates the SQL statement for creating an index if Index is true.
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 (Gin) Expression ¶
type Gist ¶
type Gist struct {
Column string
}
Gist defines a GIST index in PostgreSQL.
func (Gist) ColumnName ¶
func (Gist) Expression ¶
type Hash ¶
type Hash struct {
Column string
}
Hash defines a HASH index in PostgreSQL.
func (Hash) ColumnName ¶
func (Hash) Expression ¶
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.
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 ¶
CommentSQL generates the SQL statement for adding a comment to the JSONField.
func (*JSONField) Definition ¶
Definition generates the SQL definition for the JSONField.
func (*JSONField) IndexSQL ¶
IndexSQL generates the SQL statement for creating an index if Index or Unique is true.
type Lower ¶
type Lower struct {
Column string
}
Lower defines the LOWER expression in PostgreSQL.
func (Lower) ColumnName ¶
func (Lower) Expression ¶
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 ¶
CommentSQL generates the SQL statement for adding a comment to the TextField.
func (*TextField) Definition ¶
Definition generates the SQL definition for the TextField.
func (*TextField) IndexSQL ¶
IndexSQL generates the SQL statement for creating an index if Index is true.
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 ¶
CommentSQL generates the SQL statement for adding a comment to the TimeField.
func (*TimeField) Definition ¶
Definition generates the SQL definition for the TimeField.
func (*TimeField) IndexSQL ¶
IndexSQL generates the SQL statement for creating an index if Index is true.
type TimeOnly ¶
TimeOnly wraps a time.Time to provide custom scanning and formatting.
func (TimeOnly) MarshalJSON ¶
MarshalJSON converts the TimeOnly object to JSON.
func (*TimeOnly) UnmarshalJSON ¶
UnmarshalJSON converts JSON data to a TimeOnly object.
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 ¶
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.