Documentation
¶
Overview ¶
contains the logic for the sqgen-postgres functions command
contains the logic for the sqgen-postgres tables command
Index ¶
Constants ¶
const ( FieldTypeBoolean = "sq.BooleanField" FieldTypeJSON = "sq.JSONField" FieldTypeNumber = "sq.NumberField" FieldTypeString = "sq.StringField" FieldTypeTime = "sq.TimeField" FieldTypeEnum = "sq.EnumField" FieldTypeArray = "sq.ArrayField" FieldTypeBinary = "sq.BinaryField" FieldTypeUUID = "sq.UUIDField" FieldConstructorBoolean = "sq.NewBooleanField" FieldConstructorJSON = "sq.NewJSONField" FieldConstructorNumber = "sq.NewNumberField" FieldConstructorString = "sq.NewStringField" FieldConstructorTime = "sq.NewTimeField" FieldConstructorEnum = "sq.NewEnumField" FieldConstructorArray = "sq.NewArrayField" FieldConstructorBinary = "sq.NewBinaryField" FieldConstructorUUID = "sq.NewUUIDField" )
sq Field Types
const ( GoTypeInterface = "interface{}" GoTypeBool = "bool" GoTypeInt = "int" GoTypeFloat64 = "float64" GoTypeString = "string" GoTypeTime = "time.Time" GoTypeBoolSlice = "[]bool" GoTypeIntSlice = "[]int" GoTypeFloat64Slice = "[]float64" GoTypeStringSlice = "[]string" GoTypeTimeSlice = "[]time.Time" GoTypeByteSlice = "[]byte" )
Go Types
Variables ¶
var ( // optionally matches a [] at the end of a type in a capturing group, includes EOL match ArrayPattern = `(\[\])?$` FieldPatternBoolean = regexp.MustCompile(`boolean` + ArrayPattern) FieldPatternJSON = regexp.MustCompile(`json` + `(?:b)?` + ArrayPattern) FieldPatternInt = regexp.MustCompile( `(?:` + `smallint` + `|` + `oid` + `|` + `integer` + `|` + `bigint` + `|` + `smallserial` + `|` + `serial` + `|` + `bigserial` + `)` + ArrayPattern, ) FieldPatternFloat = regexp.MustCompile( `(?:` + `decimal` + `|` + `numeric` + `|` + `real` + `|` + `double precision` + `)` + ArrayPattern, ) FieldPatternString = regexp.MustCompile( `(?:` + `text` + `|` + `name` + `|` + `char` + `(?:\(\d+\))?` + `|` + `character` + `(?:\(\d+\))?` + `|` + `varchar` + `(?:\(\d+\))?` + `|` + `character varying` + `(?:\(\d+\))?` + `)` + ArrayPattern, ) FieldPatternTime = regexp.MustCompile( `(?:` + `date` + `|` + "timestamp" + `|` + "time" + ")" + `(?: \(\d+\))?` + `(?: without time zone| with time zone)?` + ArrayPattern, ) FieldPatternBinary = regexp.MustCompile( `bytea` + ArrayPattern, ) )
patterns used to match the types of arguments/return types of a function
Functions ¶
Types ¶
type Config ¶
type Config struct { // (required) DB URL DB *sql.DB // Package name of the file to be generated Package string // Slice of database schemas that you want to generate tables for Schemas []string // Slice of case-insensitive table names or functions to exclude from generation Exclude []string // Used to log any skipped/unsupported column types Logger sqgen.Logger }
type Function ¶
type Function struct { Schema string Name string RawResults string RawArguments string StructName string Constructor string Results []FunctionField Arguments []FunctionField }
Function contains metadata for a plpgsql function.
func (Function) Populate ¶
isDuplicate refers to if the function name is duplicated in an other schema if we have multiple function overloads within the same schema suffix the generated function with an index (starting at 1) that increments with each function overload the current overload index that we're on is the overloadCount if it is 0, means that the function is not overloaded, and we can skip adding the suffix
type FunctionField ¶
type FunctionField struct { RawField string Name string FieldType string GoType string Constructor string }
FunctionField represents a Function that is also a Field.
type FunctionsTemplateData ¶
type Table ¶
type TableField ¶
func (TableField) Populate ¶
func (field TableField) Populate() TableField
populate will fill in the .Type and .Constructor for a field based on the field's .RawType. For list of possible RawTypes that can appear, consult this link (Table 8.1): https://www.postgresql.org/docs/current/datatype.html.