tosql

package
v1.0.86 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Combinations

func Combinations(set []string) (subsets [][]string)

func EntityPrimaryKeys

func EntityPrimaryKeys(entity *nemgen.Entity) []*nemgen.Field

func EscapeValue added in v1.0.57

func EscapeValue(sql string) string

func FieldTypeToMYSQL

func FieldTypeToMYSQL(f *nemgen.Field) string

func FieldTypeToPG

func FieldTypeToPG(f *nemgen.Field) string

func GenerateFile

func GenerateFile(ctx context.Context, req *GenerateFileRequest) error

func MapEntityToTypes

func MapEntityToTypes(e *nemgen.Entity, projectVersion *nemgen.ProjectVersion, dbType db.DBType) ([]SchemaField, []SchemaIndex, []SchemaConstraint)

func PrintEntities added in v1.0.42

func PrintEntities(message string, entities []*nemgen.Entity)

func SortStandaloneEntities added in v1.0.41

func SortStandaloneEntities(pv *nemgen.ProjectVersion)

func ToCamelCase added in v1.0.83

func ToCamelCase(str string) string

ToCamelCase converts a snake_case identifier to CamelCase while keeping common initialisms (ID, UUID, JSON, URL, HTTP/HTTPS) fully upper-cased, so generated query names match go-code-gen's identifier casing (e.g. FetchProjectByUUID, not FetchProjectByUuid). Mirrors go-code-gen's strings.ToCamelCase.

Types

type Action

type Action string
const (
	SelectSimpleAction             Action = "select_simple"
	SelectForIndexedSimpleAction   Action = "select_indexed_simple"
	SelectForIndexedCombinedAction Action = "select_indexed_combined"
	InsertAction                   Action = "insert"
	UpdateAction                   Action = "update"
	DeleteAction                   Action = "delete"
	CreateAction                   Action = "create"
)

type ActionResult

type ActionResult struct {
	Action Action
	Data   string
}

type ConfigValues

type ConfigValues struct {
	DBType   db.DBType `json:"db_type"`
	Entities []string  `json:"entities"`
	Actions  []Action  `json:"actions"`
}

func ConfigValuesFromAny added in v1.0.1

func ConfigValuesFromAny(any interface{}) (*ConfigValues, error)

type GenerateDeleteForEntityWithValuesParams added in v1.0.57

type GenerateDeleteForEntityWithValuesParams struct {
	Entity         *nemgen.Entity
	ProjectVersion *nemgen.ProjectVersion
	DBType         db.DBType
	ForGolang      bool
	Keys           map[string]string // field uuid / value
}

type GenerateFileRequest

type GenerateFileRequest struct {
	ExecutionUUID string
	Configvalues  *ConfigValues
	Data          SchemaTemplate
	ActionResults *[]ActionResult
	Action        Action
	// contains filtered or unexported fields
}

type GenerateInsertForEntityWithValuesParams added in v1.0.57

type GenerateInsertForEntityWithValuesParams struct {
	Entity         *nemgen.Entity
	ProjectVersion *nemgen.ProjectVersion
	DBType         db.DBType
	ForGolang      bool
	Values         map[string]string // field uuid / value
}

type GenerateRequest

type GenerateRequest struct {
	ExecutionUUID  string
	ProjectVersion *nemgen.ProjectVersion
	Configvalues   *ConfigValues
	ForGolang      bool
}

type GenerateResponse

type GenerateResponse struct {
	ExecutionUUID string
	WorkingDir    string
	ZipFile       string
	Results       []ActionResult
}

func GenerateSQL added in v1.0.4

func GenerateSQL(ctx context.Context, req GenerateRequest) (*GenerateResponse, error)

type GenerateStatementResult added in v1.0.59

type GenerateStatementResult struct {
	SQL             string   `json:"sql"` // display only
	ParametrizedSQL string   `json:"parametrized_sql"`
	Params          []string `json:"params"`
}

func GenerateDeleteForEntityWithValues added in v1.0.57

func GenerateDeleteForEntityWithValues(ctx context.Context, params GenerateDeleteForEntityWithValuesParams) (*GenerateStatementResult, error)

func GenerateInsertForEntityWithValues added in v1.0.57

func GenerateInsertForEntityWithValues(ctx context.Context, params GenerateInsertForEntityWithValuesParams) (*GenerateStatementResult, error)

func GenerateUpdateForEntityWithValues added in v1.0.57

func GenerateUpdateForEntityWithValues(ctx context.Context, params GenerateUpdateForEntityWithValuesParams) (*GenerateStatementResult, error)

type GenerateUpdateForEntityWithValuesParams added in v1.0.57

type GenerateUpdateForEntityWithValuesParams struct {
	Entity         *nemgen.Entity
	ProjectVersion *nemgen.ProjectVersion
	DBType         db.DBType
	ForGolang      bool
	Values         map[string]string // field uuid / value
	Keys           map[string]string // field uuid / value
}

type SchemaConstraint

type SchemaConstraint struct {
	DBType       db.DBType
	Name         string
	Relationship *nemgen.Relationship
	TableName    string
	FromFields   []SchemaField
	ToFields     []SchemaField
	HasComma     bool
}

contraints

func (SchemaConstraint) ForeignKeyFields

func (sc SchemaConstraint) ForeignKeyFields() string

func (SchemaConstraint) ReferenceFields

func (sc SchemaConstraint) ReferenceFields() string

type SchemaEntity

type SchemaEntity struct {
	DBType           db.DBType
	ForGolang        bool
	Name             string
	NameTitle        string
	PrimaryKeys      []string
	Fields           []SchemaField
	Indexes          []SchemaIndex
	Constraints      []SchemaConstraint
	SelectStatements []SchemaSelectStatement
}

entity

func MapEntityToSchemaEntity added in v1.0.57

func MapEntityToSchemaEntity(e *nemgen.Entity, projectVersion *nemgen.ProjectVersion, dbType db.DBType, forGolang bool) (SchemaEntity, error)

func (SchemaEntity) IsPrimaryKey

func (e SchemaEntity) IsPrimaryKey(fieldIdentifier string) bool

func (SchemaEntity) NumOfNonePKFields added in v1.0.68

func (e SchemaEntity) NumOfNonePKFields() int

func (SchemaEntity) PrimaryKeysIdentifiers

func (e SchemaEntity) PrimaryKeysIdentifiers() string

func (SchemaEntity) PrimaryKeysWhereClause

func (e SchemaEntity) PrimaryKeysWhereClause() string

func (SchemaEntity) PrimaryKeysWhereClauseForUpdate added in v1.0.68

func (e SchemaEntity) PrimaryKeysWhereClauseForUpdate() string

func (SchemaEntity) PrimaryKeysWhereClauseParam added in v1.0.59

func (e SchemaEntity) PrimaryKeysWhereClauseParam(forGolang bool, update bool) string

func (SchemaEntity) PrimaryKeysWhereClauseWithValues added in v1.0.57

func (e SchemaEntity) PrimaryKeysWhereClauseWithValues(values map[string]string) string

func (SchemaEntity) UpdateFields

func (e SchemaEntity) UpdateFields() string

func (SchemaEntity) UpdateFieldsParam added in v1.0.59

func (e SchemaEntity) UpdateFieldsParam(forGolang bool, onlyWithValue bool, values map[string]string) string

func (SchemaEntity) UpdateFieldsWithValues added in v1.0.57

func (e SchemaEntity) UpdateFieldsWithValues(values map[string]string) string

type SchemaField

type SchemaField struct {
	Name      string
	NameTitle string
	Type      string
	Field     *nemgen.Field
	Null      string
	HasComma  bool
	Default   string
	Unique    string
}

field

func (SchemaField) Postfix

func (f SchemaField) Postfix() string

type SchemaIndex

type SchemaIndex struct {
	DBType     db.DBType
	Name       string
	FieldNames map[string]string
	Index      *nemgen.Index
	TypePrefix string
	Type       string
	TypeSort   int
	HasComma   bool
}

index

func (SchemaIndex) FieldNamesIdentifiers

func (i SchemaIndex) FieldNamesIdentifiers() string

type SchemaSelectStatement

type SchemaSelectStatement struct {
	Name             string
	Identifier       string
	EntityIdentifier string
	Fields           []SchemaSelectStatementField
	CombinedIndexes  bool
	IsPrimary        bool
	TimeFields       []SchemaField
	SortSupported    bool
}

select

func ResolveSelectStatements

func ResolveSelectStatements(e *nemgen.Entity, dbType db.DBType) []SchemaSelectStatement

type SchemaSelectStatementField

type SchemaSelectStatementField struct {
	Name   string
	Field  SchemaField
	IsLast bool
}

type SchemaTemplate

type SchemaTemplate struct {
	Entities []SchemaEntity
}

Jump to

Keyboard shortcuts

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