desc

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultTag is the default struct field tag.
	DefaultTag = "pg"
	// DefaultSearchPath is the default search path for the table.
	DefaultSearchPath = "public"
)
View Source
var (
	// ToStructName returns the struct name for the table name.
	// TODO: It can go to a NewTable function.
	ToStructName = func(tableName string) string { return PascalCase(Singular(tableName)) }
	// ToStructFieldName returns the struct field name for the column name.
	ToStructFieldName = func(columnName string) string { return PascalCase(columnName) }
	// ToColumnName returns the column name for the struct field.
	ToColumnName = func(field reflect.StructField) string { return SnakeCase(field.Name) }
)

DatabaseTableTypes is a slice of TableType that contains all the table types that are database-relative.

View Source
var PasswordAlg = "bf" // max password length: 72, salt bits: 128, output length: 60, blowfish-based.

PasswordAlg is the password algorithm the library uses to tell postgres how to generate a password field's salt. Alternatives: md5 xdes des

Functions

func BuildAlterTableForeignKeysQueries

func BuildAlterTableForeignKeysQueries(td *Table) []string

BuildAlterTableForeignKeysQueries creates ALTER TABLE queries for adding foreign key constraints.

func BuildCreateTableQuery

func BuildCreateTableQuery(td *Table) string

BuildCreateTableQuery creates a table in the database according to the given table definition.

func BuildDeleteQuery

func BuildDeleteQuery(td *Table, values []any) (string, []any, error)

BuildDeleteQuery builds and returns a SQL query for deleting one or more rows from a table.

func BuildDuplicateQuery added in v1.0.6

func BuildDuplicateQuery(td *Table, idPtr any) (string, error)

BuildDuplicateQuery returns a query that duplicates a row by its primary key.

func BuildExistsQuery

func BuildExistsQuery(td *Table, structValue reflect.Value) (string, []any, error)

BuildExistsQuery builds and returns an SQL query for checking of existing in a row in the table, based on the given struct value.

func BuildInsertQuery

func BuildInsertQuery(td *Table, structValue reflect.Value, idPtr any, forceOnConflictExpr string, upsert bool) (string, []any, error)

BuildInsertQuery builds and returns an SQL query for inserting a row into the table, based on the given struct value, arguments, and returning column. The struct value is a reflect.Value of the struct that represents the row to be inserted. The arguments are a slice of Argument that contains the column definitions and values for each field of the struct. The returning column is an optional string that specifies which column to return after the insertion, such as the primary key or any other generated value.

func BuildUpdateQuery

func BuildUpdateQuery(value any, columnsToUpdate []string, primaryKey *Column) (string, []any, error)

BuildUpdateQuery builds and returns an SQL query for updating a row in the table, using the given struct value and the primary key.

func ConvertRowsToStruct

func ConvertRowsToStruct(td *Table, rows pgx.Rows, valuePtr interface{}) error

ConvertRowsToStruct takes a table definition, a row of data from a database query, and a generic type T and returns a value of type T with the fields populated from the row data.

func ExtractPrimaryKeyValue added in v1.0.6

func ExtractPrimaryKeyValue(primaryKey *Column, structValue reflect.Value) (any, error)

ExtractPrimaryKeyValue takes a column definition and a reflect value of a struct

func IndirectType

func IndirectType(typ reflect.Type) reflect.Type

IndirectType returns the value of a pointer-type "typ". If "typ" is a pointer, array, chan, map or slice it returns its Elem, otherwise returns the "typ" as it is.

func IndirectValue

func IndirectValue(v any) reflect.Value

IndirectValue returns the element type (e.g. if pointer of *User it will return the User type).

func PascalCase

func PascalCase(snake string) string

PascalCase converts a given string to a friendly pascal case, e.g. - user_id to UserID - id to ID - provider_api_key to ProviderAPIKey - customer_provider to CustomerProvider

func RegisterDataType

func RegisterDataType(t DataType, names ...string)

RegisterDataType registers a new data type with the given names. It panics if the data type or any of the names already exists. This function is used to extend the supported data types by custom ones.

func RowToStruct

func RowToStruct[T any](td *Table, rows pgx.Rows) (value T, err error)

RowToStruct takes a schema, a single row of data from a database query, and a generic type T and returns a value of type T with the fields populated from the row data.

func RowsToStruct

func RowsToStruct[T any](td *Table, rows pgx.Rows) ([]T, error)

RowsToStruct takes a schema, a row of data from a database query, and a generic type T and returns a slice of values of type T with the fields populated from the row data.

func Singular

func Singular(s string) string

Singular returns the singular form of the given string.

func SnakeCase

func SnakeCase(camel string) string

SnakeCase converts a given string to a friendly snake case, e.g. - userId to user_id - ID to id - ProviderAPIKey to provider_api_key - Option to option

Types

type Argument

type Argument struct {
	Column *Column // the column definition for the argument
	Value  any     // the value for the argument
}

Argument represents a single argument for a database query It contains a column definition and a value.

type Arguments

type Arguments []Argument

Arguments is a slice of Argument.

func (*Arguments) ShiftEnd added in v1.0.3

func (args *Arguments) ShiftEnd(arg Argument)

ShiftEnd moves the argument with the given column name to the end of the slice.

func (Arguments) Values

func (args Arguments) Values() []any

Values returns a slice of values from the arguments.

type CheckConstraint

type CheckConstraint struct {
	Expression string
}

CheckConstraint is a type that represents a check constraint.

type Column

type Column struct {
	Table            *Table    // the parent table reference.
	TableName        string    // the name of the table this column lives at.
	TableDescription string    // the description of the table this column lives at.
	TableType        TableType // the type of the table this column lives at.

	Name            string       // the name of the column
	Type            DataType     // the data type of the column
	Description     string       // the description of the column
	OrdinalPosition int          // the position (starting from 1) of the corresponding column in the table.
	FieldIndex      []int        // the index of the corresponding struct field
	FieldType       reflect.Type // the reflect.Type of the corresponding struct field
	/* if nil then wasn't able to resolve it by builtin method */
	FieldName    string // the name of the corresponding struct field
	TypeArgument string // an optional argument for the data type, e.g. 255 when Type is "varchar"
	PrimaryKey   bool   // a flag that indicates if the column is a primary key
	Identity     bool   // a flag that indicates if the column is an identity column, e.g. INT GENERATED ALWAYS AS IDENTITY
	// Required        bool         // a flag that indicates if the column is required (not null, let's just use the !Nullable)
	Default         string // an optional default value or sql function for the column
	CheckConstraint string // an optional check constraint for the column
	Unique          bool   // a flag that indicates if the column has a unique constraint (postgres automatically adds an index for that single one)
	// As tested, the unique=true and a single column of unique_index is the same result in the database on table creation,
	// note that because the generator does store unique_index instead of simple unique on Go generated source files.
	Conflict string // an optional conflict action for the unique constraint, e.g do nothing

	// If true this and password field is used to SelectByUsernameAndPassword repository method.
	Username bool
	// If true Postgres handles password encryption (on inserts) and decryption (on selects),
	// note that you MUST set the Schema.HandlePassword in order for this to work by both ways.
	// A flag that indicates if the column is a password column.
	Password bool
	// If true it's a shorthand of default="null".
	Nullable            bool   // a flag that indicates if the column is nullable
	ReferenceTableName  string // an optional reference table name for a foreign key constraint, e.g. user_profiles(id) -> user_profiles
	ReferenceColumnName string // an optional reference column name for a foreign key constraint, e.g. user_profiles(id) -> id
	DeferrableReference bool   // a flag that indicates if the foreign key constraint is deferrable (omits foreign key checks on transactions)
	ReferenceOnDelete   string // an optional action for deleting referenced rows when referencing rows are deleted, e.g. NO ACTION, RESTRICT, CASCADE, SET NULL and SET DEFAULT. Defaults to CASCADE.

	Index IndexType // an optional index type for the column

	// Unique indexes can really improve the performance on big data select queries
	// Read more at: https://www.postgresql.org/docs/current/indexes-unique.html
	UniqueIndex string // an optional name for a unique index on the column
	// If true then create table, insert, update and duplicate queries will omit this column.
	Presenter bool
	// If true then insert query will omit this column.
	AutoGenerated bool
	// If true then this column->struct value is skipped from the Select queries
	Unscannable bool // a flag that indicates if the column is unscannable
}

Column is a type that represents a column definition for the database.

func (*Column) FieldTagString

func (c *Column) FieldTagString(strict bool) string

FieldTagString returns a string representation of the struct field tag for the column.

func (*Column) IsGenerated added in v1.0.6

func (c *Column) IsGenerated() bool

IsGenerated returns true if the column is a generated column.

func (*Column) IsGeneratedPrimaryUUID

func (c *Column) IsGeneratedPrimaryUUID() bool

IsGeneratedPrimaryUUID returns true if the column is a primary UUID column and has a default value of "gen_random_uuid()" or "uuid_generate_v4()".

func (*Column) IsGeneratedTimestamp

func (c *Column) IsGeneratedTimestamp() bool

IsGeneratedTimestamp returns true if the column is a timestamp column and has a default value of "clock_timestamp()" or "now()".

type ColumnBasicInfo

type ColumnBasicInfo struct {
	TableName        string
	TableDescription string
	TableType        TableType
	Name             string
	OrdinalPosition  int
	Description      string
	Default          string
	DataType         DataType
	DataTypeArgument string
	IsNullable       bool
	IsIdentity       bool
	IsGenerated      bool
}

ColumnBasicInfo represents a basic column information, contains the table name, column name, ordinal position, column default value, data type, data type argument, whether the column is nullable, whether the column is identity and whether the column is generated.

func (*ColumnBasicInfo) BuildColumn

func (c *ColumnBasicInfo) BuildColumn(column *Column) error

type ColumnBuilder

type ColumnBuilder interface {
	BuildColumn(*Column) error
}

ColumnBuilder is an interface that is used to build a column definition.

type ColumnFilter

type ColumnFilter func(*Column) bool

ColumnFilter is a function that returns whether this column should be live inside a table.

type Constraint

type Constraint struct {
	TableName  string
	ColumnName string

	ConstraintName string
	ConstraintType ConstraintType

	IndexType IndexType

	Unique     *UniqueConstraint
	Check      *CheckConstraint
	ForeignKey *ForeignKeyConstraint
}

Constraint is a type that represents a constraint.

func (*Constraint) Build

func (c *Constraint) Build(constraintDefinition string)

Build implements the ColumnBuilder interface.

func (*Constraint) BuildColumn

func (c *Constraint) BuildColumn(column *Column) error

BuildColumn implements the ColumnBuilder interface.

func (*Constraint) String

func (c *Constraint) String() string

String implements the fmt.Stringer interface.

type ConstraintType

type ConstraintType uint8

ConstraintType is a type that represents a constraint type.

const (
	// NoneConstraintType is a constraint type that represents no constraint.
	NoneConstraintType ConstraintType = iota
	// PrimaryKeyConstraintType is a constraint type that represents a primary key constraint.
	PrimaryKeyConstraintType
	// UniqueConstraintType is a constraint type that represents a unique constraint.
	UniqueConstraintType
	// ForeignKeyConstraintType is a constraint type that represents a foreign key constraint.
	ForeignKeyConstraintType
	// CheckConstraintType is a constraint type that represents a check constraint.
	CheckConstraintType
	// IndexConstraintType is a constraint type that represents a simple index constraint.
	IndexConstraintType // A custom type to represent a simple index, see ListConstraints.
)

func (*ConstraintType) Scan

func (t *ConstraintType) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

type DataType

type DataType uint8

DataType represents the sql data type for a column.

const (
	InvalidDataType DataType = iota // InvalidDataType is a placeholder for an invalid data type.
	BigInt                          // BigInt represents a signed 64-bit integer.
	BigIntArray                     // BigIntArray represents an array of signed 64-bit integers.
	BigSerial                       // BigSerial represents a 64-bit auto-incrementing integer.
	Bit                             // Bit represents a fixed-length bit string.
	BitVarying                      // BitVarying represents a variable-length bit string.
	Boolean                         // Boolean represents a logical value (true or false).
	Box                             // Box represents a rectangular box on a plane.
	Bytea                           // Bytea represents a binary string (byte array).
	Character                       // Character represents a fixed-length character string.
	CharacterArray
	CharacterVarying      // CharacterVarying represents a variable-length character string.
	CharacterVaryingArray // CharacterVaryingArray represents an array of variable-length character strings.
	Cidr                  // Cidr represents an IPv4 or IPv6 network address.
	Circle                // Circle represents a circle on a plane.
	Date                  // Date represents a calendar date (year, month, day).
	DoublePrecision       // DoublePrecision represents a double-precision floating-point number (8 bytes).
	Inet                  // Inet represents an IPv4 or IPv6 host address.
	Integer               // Integer represents a signed 32-bit integer.
	IntegerArray          // IntegerArray represents an array of signed 32-bit integers.
	IntegerDoubleArray    // IntegerDoubleArray represents an array of arrays of signed 32-bit integers.
	Array                 // Array represents an array of any dimension.
	Interval              // Interval represents a time span.
	JSON                  // JSON represents a JSON data structure in text format.
	JSONB                 // JSONB represents a JSON data structure in binary format.
	Line                  // Line represents an infinite line on a plane.
	Lseg                  // Lseg represents a line segment on a plane.
	MACAddr               // MACAddr represents a MAC (Media Access Control) address (6 bytes).
	MACAddr8              // MACAddr8 represents an EUI-64 MAC address (8 bytes).
	Money                 // Money represents a currency amount with fixed fractional precision.
	Numeric               // Numeric represents an exact numeric value with variable precision and scale.
	Path                  // Path represents a geometric path on a plane. It can be open or closed, and can have multiple subpaths.
	PgLSN                 // PgLSN represents a PostgreSQL Log Sequence Number, which is used to identify log positions in the write-ahead log (WAL).
	Point                 // Point represents a geometric point on a plane. It has two coordinates: x and y.
	Polygon               // Polygon represents a closed geometric path on a plane. It consists of one or more points that form the vertices of the polygon.
	Real                  // Real represents a single-precision floating-point number (4 bytes).
	SmallInt              // SmallInt represents a signed 16-bit integer.
	SmallSerial           // SmallSerial represents a 16-bit auto-incrementing integer.
	Serial                // Serial represents a 32-bit auto-incrementing integer.
	Text                  // Text represents a variable-length character string with unlimited length.
	TextArray             // TextArray represents an array of variable-length character strings with unlimited length.
	TextDoubleArray       // TextDoubleArray represents an array of arrays of variable-length character strings with unlimited length.
	Time                  // Time represents the time of day (without time zone).
	TimeTZ                // TimeTZ represents the time of day (with time zone).
	Timestamp             // Timestamp represents the date and time of day (without time zone).
	TimestampTZ           // TimestampTZ represents the date and time of day (with time zone).
	TsQuery               // TsQuery represents a text search query that can be used to search tsvector values.
	TsVector              // TsVector represents a text search document that contains lexemes and their positions.
	TxIDSnapshot          // TxIDSnapshot represents the state of transactions at some point in time. It can be used to implement multiversion concurrency control (MVCC).
	UUID                  // UUID represents an universally unique identifier (16 bytes).
	UUIDArray             // UUIDArray represents an array of universally unique identifiers (16 bytes).
	XML                   // XML represents an XML data structure in text format.
	// Multiranges: https://www.postgresql.org/docs/14/rangetypes.html#RANGETYPES-BUILTIN.
	Int4Range // Range of integer, int4multirange.
	Int4MultiRange
	Int8Range // Range of bigint, int8multirange.
	Int8MultiRange
	NumRange // Range of numeric, nummultirange.
	NumMultiRange
	TsRange // Range of timestamp without time zone, tsmultirange.
	TsMultirange
	TsTzRange // Range of timestamp with time zone, tstzmultirange.
	TsTzMultiRange
	DateRange // Range of date, datemultirange.
	DateMultiRange
	//
	CIText // CIText is an extension data type that provides case-insensitive
	HStore // hstore is an extension data type that provides key-value into a single column.
)

Available data types.

func ParseDataType

func ParseDataType(s string) (DataType, string)

ParseDataType converts a string to a DataType value, ignoring case and parentheses. It returns Invalid if the string does not match any of the registered data types.

func (DataType) GoType

func (t DataType) GoType() reflect.Type

GoType returns the Go type for the data type.

func (DataType) IsArray

func (t DataType) IsArray() bool

IsArray returns true if the data type is an array.

func (DataType) IsString

func (t DataType) IsString(s string) bool

IsString returns true if the given string matches any of the names of the data type, ignoring case and whitespace.

func (DataType) IsTime added in v1.0.7

func (t DataType) IsTime() bool

IsTime returns true if the data type is a time type.

func (DataType) String

func (t DataType) String() string

String returns the first name of the data type, or a formatted string if the data type is unexpected.

type Expression

type Expression struct {
	Input           string
	ResultFieldType reflect.Type
}

Expression is a filter expression.

func NewExpression

func NewExpression(input string, fieldType reflect.Type) Expression

NewExpression returns a new Expression.

type Expressions

type Expressions []Expression

Expressions is a slice of expressions.

func (Expressions) FilterTable

func (expressions Expressions) FilterTable(t *Table) bool

FilterTable implements the TableFilter interface.

type ForeignKeyConstraint

type ForeignKeyConstraint struct {
	// the name of the column that references another table,
	// this is the same as the column name of the Constraint type but
	// it's here because we use this type internally and solo as well.
	ColumnName string

	ReferenceTableName  string // the name of the table that is referenced by the foreign key
	ReferenceColumnName string // the name of the column that is referenced by the foreign key
	OnDelete            string // the action to take when the referenced row is deleted
	Deferrable          bool   // whether the foreign key constraint is deferrable or not
}

ForeignKeyConstraint is a type that represents a foreign key definition for a column. A foreign key is a constraint that establishes a link between two tables based on a column or a set of columns. A foreign key can have different options for handling the deletion or update of the referenced row, such as cascade, restrict, set null, etc. A foreign key can also be deferrable, meaning that the constraint can be checked at the end of a transaction instead of immediately.

type Index

type Index struct {
	TableName  string
	ColumnName string

	Name string
	Type IndexType
}

Index is a type that represents an index definition for a column. An index is a data structure that improves the speed of data retrieval operations on a table. An index can be of different types, such as B-tree, hash, etc.

type IndexType

type IndexType uint8

IndexType is an enumeration type that represents different types of indexes in a database.

const (
	InvalidIndex IndexType = iota // InvalidIndex is the zero value for IndexType and indicates an invalid or unknown index type
	Btree                         // Btree is an index type that uses a balanced tree data structure
	Hash                          // Hash is an index type that uses a hash table data structure
	Gist                          // Gist is an index type that supports generalized search trees for various data types
	Spgist                        // Spgist is an index type that supports space-partitioned generalized search trees for various data types
	Gin                           // Gin is an index type that supports inverted indexes for various data types
	Brin                          // Brin is an index type that supports block range indexes for large tables
)

These are the possible values for IndexType.

func (*IndexType) Scan

func (t *IndexType) Scan(src interface{}) error

func (IndexType) String

func (t IndexType) String() string

String returns the string representation of an IndexType value.

type PasswordHandler

type PasswordHandler struct {
	// Encrypt takes a table name and a plain password as strings and returns an encrypted password as a string.
	Encrypt func(tableName, plainPassword string) (encryptedPassword string, err error)
	// Decrypt takes a table name and an encrypted password as strings and returns a plain password as a string.
	Decrypt func(tableName, encryptedPassword string) (plainPassword string, err error)
}

PasswordHandler is a type that represents a password handler for the database.

type Table

type Table struct {
	RegisteredPosition int // the position of the table in the schema
	Type               TableType

	StructName  string       // the name of the struct that represents the table
	StructType  reflect.Type `json:"-"` // the type of the struct that represents the table
	SearchPath  string       // the search path for the table
	Name        string       // the name of the table
	Description string       // the description of the table
	Strict      bool         // if true then the select queries will return an error if a column is missing from the struct's fields
	Columns     []*Column    // a slice of pointers to Column that represents the columns of the table

	PasswordHandler *PasswordHandler
}

Table is a type that represents a table definition for the database.

func ConvertStructToTable

func ConvertStructToTable(tableName string, typ reflect.Type) (*Table, error)

ConvertStructToTable takes a table name and a reflect.Type that represents a struct type and returns a pointer to a Table that represents a table definition for the database or an error if the conversion fails.

func (*Table) AddColumns

func (td *Table) AddColumns(columns ...*Column)

AddColumns adds the given columns to the table definition.

func (*Table) ColumnExists

func (td *Table) ColumnExists(name string) bool

ColumnExists returns true if the table definition contains a column.

func (*Table) FilterColumns

func (td *Table) FilterColumns(filter ColumnFilter)

FilterColumns this will modify the columns list and the columns fields. Used internally by gen tool to apply the custom type resolver into the table.

func (*Table) ForeignKeyColumnNames

func (td *Table) ForeignKeyColumnNames() []string

ForeignKeyColumnNames returns a slice of column names that have a foreign key reference to another table.

func (*Table) ForeignKeys

func (td *Table) ForeignKeys() []ForeignKeyConstraint

ForeignKeys returns a slice of ForeignKey for the table definition, based on the ReferenceTableName field of each column.

func (*Table) GetColumnByName

func (td *Table) GetColumnByName(name string) *Column

GetColumnByName returns the column definition with the given name, or nil if no such column exists in the table definition. The name comparison is case-insensitive.

func (*Table) GetPasswordColumn

func (td *Table) GetPasswordColumn() *Column

GetPasswordColumn returns the first column marked as password.

func (*Table) GetUsernameColumn

func (td *Table) GetUsernameColumn() *Column

GetUsernameColumn returns the first column marked as username.

func (*Table) Indexes

func (td *Table) Indexes() []*Index

Indexes returns a slice of Index for the table definition, based on the Index field of each column.

func (*Table) IsReadOnly

func (td *Table) IsReadOnly() bool

IsReadOnly returns true if the table is a simple view or materialized view.

func (*Table) IsType

func (td *Table) IsType(typesToCheck ...TableType) bool

IsType returns true if the table is one of the given types (true if no typesToCheck provided).

func (*Table) ListColumnNames

func (td *Table) ListColumnNames() []string

ListColumnNames returns the column names of the table definition.

func (*Table) ListColumnNamesExcept added in v1.0.3

func (td *Table) ListColumnNamesExcept(except ...string) []string

ListColumnNamesExcept returns the column names of the table definition except the given ones.

func (*Table) ListColumnsWithoutGenerated added in v1.0.6

func (td *Table) ListColumnsWithoutGenerated() []*Column

ListColumnsWithoutGenerated returns the columns of the table definition except the generated ones.

func (*Table) ListColumnsWithoutPresenter added in v1.0.9

func (td *Table) ListColumnsWithoutPresenter() []*Column

ListColumnsWithoutPresenter returns the columns of the table definition except the presenter ones.

func (*Table) ListImportPaths

func (td *Table) ListImportPaths() []string

ListImportPaths returns a slice of import paths for the table definition, based on the FieldType field of each column.

func (*Table) OnConflict

func (td *Table) OnConflict() (string, bool)

OnConflict returns the first (and only one valid) ON CONFLICT=$Conflict. This is used to specify what action to take when a row conflicts with an existing row in the table.

func (*Table) PrimaryKey

func (td *Table) PrimaryKey() (*Column, bool)

PrimaryKey returns the primary key's column of the row definition and reports if there is one.

func (*Table) RemoveColumns

func (td *Table) RemoveColumns(columnNames ...string)

RemoveColumns removes the columns with the given names from the table definition.

func (*Table) SetStrict

func (td *Table) SetStrict(v bool) *Table

SetStrict sets the strict flag of the table definition to the given value, and returns the table definition itself for chaining. The strict flag determines whether the table definition allows extra fields that are not defined in the columns.

func (*Table) UniqueIndexes

func (td *Table) UniqueIndexes() UniqueIndexes

UniqueIndexes returns a UniqueIndexes map for the table definition, based on the UniqueIndex field of each column.

type TableFilter

type TableFilter interface {
	// FilterTable returns true if the table should be filtered out.
	FilterTable(*Table) bool
}

TableFilter is an interface that table loopers should implement.

type TableFilterFunc

type TableFilterFunc func(*Table) bool

TableFilterFunc is a function that implements the TableFilter interface.

func (TableFilterFunc) FilterTable

func (fn TableFilterFunc) FilterTable(t *Table) bool

FilterTable implements the TableFilter interface.

type TableType

type TableType uint8

TableType is a type that represents the type of a table.

const (
	// TableTypeBase is the default table type.
	TableTypeBase TableType = iota
	// TableTypeView is the view table type.
	// The table is read-only.
	TableTypeView
	// TableTypeMaterializedView is the materialized view table type.
	// The table is read-only but it can be refreshed.
	TableTypeMaterializedView
	// TableTypePresenter is the presenter table type.
	// It's not a view neither a normal table.
	// It can be used to decode custom select queries.
	TableTypePresenter
)

func ParseTableType

func ParseTableType(s string) TableType

ParseTableType parses the given string and returns the corresponding TableType.

func (TableType) IsReadOnly

func (t TableType) IsReadOnly() bool

IsReadOnly returns true if the table is a simple view or materialized view.

func (TableType) IsRefreshable

func (t TableType) IsRefreshable() bool

IsRefreshable returns true if the table is a materialized view.

type Trigger

type Trigger struct {
	Catalog           string // Catalog name of the trigger
	SearchPath        string // Search path of the trigger
	Name              string // Name of the trigger
	Manipulation      string // Type of manipulation (INSERT, UPDATE, DELETE)
	TableName         string // Name of the table the trigger is on
	ActionStatement   string // SQL statement executed by the trigger
	ActionOrientation string // Orientation of the trigger (ROW or STATEMENT)
	ActionTiming      string // Timing of the trigger (BEFORE or AFTER)
}

Trigger represents a database trigger.

type UniqueConstraint

type UniqueConstraint struct {
	Columns []string
}

UniqueConstraint is a type that represents a unique constraint.

type UniqueIndex added in v1.0.6

type UniqueIndex struct {
	TableName string   // table name
	IndexName string   // index name
	Columns   []string // column names.
}

UniqueIndex is a struct that represents a unique index. See DB.ListUniqueIndexes method for more.

type UniqueIndexes

type UniqueIndexes map[string][]string /* key = index name, value = set of columns */

UniqueIndexes is a type that represents a map of unique index names to column names. A unique index is a constraint that ensures that no two rows in a table have the same values for a set of columns.

type Zeroer

type Zeroer interface {
	IsZero() bool // IsZero returns true if the value is zero
}

Zeroer is an interface that defines a method to check if a value is zero.

Zeroer can be implemented by custom types to report whether its current value is zero. Standard Time also implements that.

Jump to

Keyboard shortcuts

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