Additional documentation for sub packages.
This commit is contained in:
parent
b10270b502
commit
556578cec9
19 changed files with 111 additions and 77 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package metadata
|
||||
|
||||
// MetaData interface
|
||||
type MetaData interface {
|
||||
Name() string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package postgres_metadata
|
||||
package postgresmeta
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
// ColumnInfo metadata struct
|
||||
type ColumnInfo struct {
|
||||
Name string
|
||||
IsNullable bool
|
||||
|
|
@ -14,6 +15,7 @@ type ColumnInfo struct {
|
|||
EnumName string
|
||||
}
|
||||
|
||||
// SqlBuilderColumnType returns type of jet sql builder column
|
||||
func (c ColumnInfo) SqlBuilderColumnType() string {
|
||||
switch c.DataType {
|
||||
case "boolean":
|
||||
|
|
@ -41,6 +43,7 @@ func (c ColumnInfo) SqlBuilderColumnType() string {
|
|||
}
|
||||
}
|
||||
|
||||
// GoBaseType returns model type for column info.
|
||||
func (c ColumnInfo) GoBaseType() string {
|
||||
switch c.DataType {
|
||||
case "USER-DEFINED":
|
||||
|
|
@ -72,6 +75,8 @@ func (c ColumnInfo) GoBaseType() string {
|
|||
}
|
||||
}
|
||||
|
||||
// GoModelType returns model type for column info with optional pointer if
|
||||
// column can be NULL.
|
||||
func (c ColumnInfo) GoModelType() string {
|
||||
typeStr := c.GoBaseType()
|
||||
if c.IsNullable {
|
||||
|
|
@ -81,6 +86,7 @@ func (c ColumnInfo) GoModelType() string {
|
|||
return typeStr
|
||||
}
|
||||
|
||||
// GoModelTag returns model field tag for column
|
||||
func (c ColumnInfo) GoModelTag(isPrimaryKey bool) string {
|
||||
tags := []string{}
|
||||
|
||||
|
|
@ -1,15 +1,17 @@
|
|||
package postgres_metadata
|
||||
package postgresmeta
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"github.com/go-jet/jet/generator/internal/metadata"
|
||||
)
|
||||
|
||||
// EnumInfo struct
|
||||
type EnumInfo struct {
|
||||
name string
|
||||
Values []string
|
||||
}
|
||||
|
||||
// Name returns enum name
|
||||
func (e EnumInfo) Name() string {
|
||||
return e.name
|
||||
}
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
package postgres_metadata
|
||||
package postgresmeta
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"github.com/go-jet/jet/generator/internal/metadata"
|
||||
)
|
||||
|
||||
// SchemaInfo metadata struct
|
||||
type SchemaInfo struct {
|
||||
DatabaseName string
|
||||
Name string
|
||||
|
|
@ -12,6 +13,7 @@ type SchemaInfo struct {
|
|||
EnumInfos []metadata.MetaData
|
||||
}
|
||||
|
||||
// GetSchemaInfo returns schema information from db connection.
|
||||
func GetSchemaInfo(db *sql.DB, databaseName, schemaName string) (schemaInfo SchemaInfo, err error) {
|
||||
|
||||
schemaInfo.DatabaseName = databaseName
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
package postgres_metadata
|
||||
package postgresmeta
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"github.com/go-jet/jet/internal/utils"
|
||||
)
|
||||
|
||||
// TableInfo metadata struct
|
||||
type TableInfo struct {
|
||||
SchemaName string
|
||||
name string
|
||||
|
|
@ -12,14 +13,17 @@ type TableInfo struct {
|
|||
Columns []ColumnInfo
|
||||
}
|
||||
|
||||
// Name returns table info name
|
||||
func (t TableInfo) Name() string {
|
||||
return t.name
|
||||
}
|
||||
|
||||
func (t TableInfo) IsPrimaryKey(columnName string) bool {
|
||||
return t.PrimaryKeys[columnName]
|
||||
// IsPrimaryKey returns if column is a part of primary key
|
||||
func (t TableInfo) IsPrimaryKey(column string) bool {
|
||||
return t.PrimaryKeys[column]
|
||||
}
|
||||
|
||||
// MutableColumns returns list of mutable columns for table
|
||||
func (t TableInfo) MutableColumns() []ColumnInfo {
|
||||
ret := []ColumnInfo{}
|
||||
|
||||
|
|
@ -34,6 +38,7 @@ func (t TableInfo) MutableColumns() []ColumnInfo {
|
|||
return ret
|
||||
}
|
||||
|
||||
// GetImports returns model imports for table.
|
||||
func (t TableInfo) GetImports() []string {
|
||||
imports := map[string]string{}
|
||||
|
||||
|
|
@ -57,10 +62,12 @@ func (t TableInfo) GetImports() []string {
|
|||
return ret
|
||||
}
|
||||
|
||||
// GoStructName returns go struct name for sql builder
|
||||
func (t TableInfo) GoStructName() string {
|
||||
return utils.ToGoIdentifier(t.name) + "Table"
|
||||
}
|
||||
|
||||
// GetTableInfo returns table info metadata
|
||||
func GetTableInfo(db *sql.DB, dbName, schemaName, tableName string) (tableInfo TableInfo, err error) {
|
||||
|
||||
tableInfo.SchemaName = schemaName
|
||||
Loading…
Add table
Add a link
Reference in a new issue