Documentation
¶
Index ¶
- type ColumnData
- type EnumData
- type IndexData
- type TableData
- type TemplateData
- type Templates
- type TypeMapper
- func (tm *TypeMapper) BuildColumnChain(col *models.Column, table *models.Table, isEnum bool) string
- func (tm *TypeMapper) BuildReferencesChain(fk *models.Constraint, referencedTable string) string
- func (tm *TypeMapper) DrizzleTypeToTypeScript(drizzleType string, isEnum bool, enumName string) string
- func (tm *TypeMapper) SQLTypeToDrizzle(sqlType string) string
- func (tm *TypeMapper) ToCamelCase(s string) string
- func (tm *TypeMapper) ToPascalCase(s string) string
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ColumnData ¶
type ColumnData struct {
Name string // Column name in database
FieldName string // Field name in TypeScript (camelCase)
DrizzleChain string // Complete Drizzle column chain (e.g., "integer('id').primaryKey()")
TypeScriptType string // TypeScript type for interface (e.g., "string", "number | null")
IsForeignKey bool // Whether this is a foreign key
ReferencesLine string // The .references() line if FK
Comment string // Column comment
}
ColumnData represents a column in a table
func NewColumnData ¶
func NewColumnData(col *models.Column, table *models.Table, tm *TypeMapper, isEnum bool) *ColumnData
NewColumnData creates ColumnData from a models.Column
type EnumData ¶
type EnumData struct {
Name string // Enum name (PascalCase)
VarName string // Variable name for the enum (camelCase)
Values []string // Enum values
ValuesStr string // Comma-separated quoted values for pgEnum()
TypeUnion string // TypeScript union type (e.g., "'admin' | 'user' | 'guest'")
SchemaName string // Schema name
}
EnumData represents an enum in the schema
func NewEnumData ¶
func NewEnumData(enum *models.Enum, tm *TypeMapper) *EnumData
NewEnumData creates EnumData from a models.Enum
type IndexData ¶
type IndexData struct {
Name string // Index name
Columns []string // Column names
IsUnique bool // Whether it's a unique index
Definition string // Complete index definition line
}
IndexData represents an index definition
func NewIndexData ¶
func NewIndexData(index *models.Index, tableVar string, tm *TypeMapper) *IndexData
NewIndexData creates IndexData from a models.Index
type TableData ¶
type TableData struct {
Name string // Table variable name (camelCase, e.g., users)
TableName string // Actual database table name (e.g., users)
TypeName string // TypeScript type name (PascalCase, e.g., Users)
Columns []*ColumnData // Column definitions
Indexes []*IndexData // Index definitions
Comment string // Table comment
SchemaName string // Schema name
NeedsSQLTag bool // Whether we need to import 'sql' from drizzle-orm
IndexColumnFields []string // Column field names used in indexes (for destructuring)
}
TableData represents a table in the template
func NewTableData ¶
func NewTableData(table *models.Table, tm *TypeMapper) *TableData
NewTableData creates TableData from a models.Table
func (*TableData) AddColumn ¶
func (td *TableData) AddColumn(col *ColumnData)
AddColumn adds a column to the table data
type TemplateData ¶
TemplateData represents the data passed to the template for code generation
func NewTemplateData ¶
func NewTemplateData() *TemplateData
NewTemplateData creates a new TemplateData
func (*TemplateData) AddEnum ¶
func (td *TemplateData) AddEnum(enum *EnumData)
AddEnum adds an enum to the template data
func (*TemplateData) AddImport ¶
func (td *TemplateData) AddImport(importLine string)
AddImport adds an import to the template data (deduplicates automatically)
func (*TemplateData) AddTable ¶
func (td *TemplateData) AddTable(table *TableData)
AddTable adds a table to the template data
func (*TemplateData) FinalizeImports ¶
func (td *TemplateData) FinalizeImports()
FinalizeImports sorts imports
type Templates ¶
type Templates struct {
// contains filtered or unexported fields
}
Templates holds the parsed templates
func NewTemplates ¶
NewTemplates creates and parses the templates
func (*Templates) GenerateCode ¶
func (t *Templates) GenerateCode(data *TemplateData) (string, error)
GenerateCode executes the template with the given data
type TypeMapper ¶
type TypeMapper struct{}
TypeMapper handles SQL to Drizzle type conversions
func NewTypeMapper ¶
func NewTypeMapper() *TypeMapper
NewTypeMapper creates a new TypeMapper instance
func (*TypeMapper) BuildColumnChain ¶
BuildColumnChain builds the complete column definition chain for Drizzle Example: integer('id').primaryKey().notNull()
func (*TypeMapper) BuildReferencesChain ¶
func (tm *TypeMapper) BuildReferencesChain(fk *models.Constraint, referencedTable string) string
BuildReferencesChain builds the .references() chain for foreign key columns
func (*TypeMapper) DrizzleTypeToTypeScript ¶
func (tm *TypeMapper) DrizzleTypeToTypeScript(drizzleType string, isEnum bool, enumName string) string
DrizzleTypeToTypeScript converts Drizzle column types to TypeScript types
func (*TypeMapper) SQLTypeToDrizzle ¶
func (tm *TypeMapper) SQLTypeToDrizzle(sqlType string) string
SQLTypeToDrizzle converts SQL types to Drizzle column type functions Returns the Drizzle column constructor (e.g., "integer", "varchar", "text")
func (*TypeMapper) ToCamelCase ¶
func (tm *TypeMapper) ToCamelCase(s string) string
ToCamelCase converts snake_case or PascalCase to camelCase
func (*TypeMapper) ToPascalCase ¶
func (tm *TypeMapper) ToPascalCase(s string) string
ToPascalCase converts snake_case to PascalCase
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer implements the writers.Writer interface for Drizzle ORM
func NewWriter ¶
func NewWriter(options *writers.WriterOptions) *Writer
NewWriter creates a new Drizzle writer with the given options
func (*Writer) WriteDatabase ¶
WriteDatabase writes a complete database as Drizzle schema
func (*Writer) WriteSchema ¶
WriteSchema writes a schema as Drizzle schema