schema

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Access added in v0.0.3

type Access string

Access narrows what a contract allows. Empty means both read and write.

const (
	AccessFull  Access = ""
	AccessRead  Access = "read"
	AccessWrite Access = "write"
)

type Contract

type Contract struct {
	Type   ContractType
	Access Access
}

type ContractType

type ContractType string
const (
	ContractSQLC  ContractType = "sqlc"
	ContractPROTO ContractType = "proto"
)

type Entity

type Entity struct {
	Name      string
	Comment   string
	Fields    []Field
	Contracts []Contract
	Queries   []Query
	Indexes   []Index
}

func FilterPROTO

func FilterPROTO(entities []Entity) []Entity

func FilterSQLC

func FilterSQLC(entities []Entity) []Entity

func (Entity) CanFieldRead added in v0.0.3

func (e Entity) CanFieldRead(field Field) bool

func (Entity) CanFieldWrite added in v0.0.3

func (e Entity) CanFieldWrite(field Field) bool

func (Entity) GetContract added in v0.0.3

func (e Entity) GetContract(contractType ContractType) (Contract, bool)

func (Entity) GetFieldByName

func (e Entity) GetFieldByName(name string) (Field, bool)

func (Entity) GetIdField

func (e Entity) GetIdField() Field

func (Entity) HasPROTO

func (e Entity) HasPROTO() bool

func (Entity) HasSQLC

func (e Entity) HasSQLC() bool

func (Entity) IsFieldVirtual added in v0.0.3

func (e Entity) IsFieldVirtual(field Field) bool

func (Entity) ProtoQueries added in v0.0.3

func (e Entity) ProtoQueries() []Query

ProtoQueries returns the queries generated for the proto contract

func (Entity) SQLCQueries added in v0.0.3

func (e Entity) SQLCQueries() []Query

SQLCQueries returns the queries generated for the sqlc contract

type Field

type Field struct {
	Name         string
	Type         FieldType
	Primary      bool
	Unique       bool
	DefaultValue any
	DefaultFunc  func() any
	ProtoField   int
	Comment      string
	Contracts    []Contract
	Immutable    bool
	Optional     bool
	Validate     func() any
}

func (Field) CanApiRead added in v0.0.3

func (f Field) CanApiRead() bool

func (Field) CanApiWrite added in v0.0.3

func (f Field) CanApiWrite() bool

func (Field) CanDbRead added in v0.0.3

func (f Field) CanDbRead() bool

func (Field) CanDbWrite added in v0.0.3

func (f Field) CanDbWrite() bool

func (Field) GetContract added in v0.0.3

func (f Field) GetContract(contractType ContractType) (Contract, bool)

GetContract returns the field contract of the given type

func (Field) IsID

func (f Field) IsID() bool

func (Field) IsVirtual

func (f Field) IsVirtual() bool

IsVirtual reports a field that lives only in proto and not in sqlc.

type FieldType

type FieldType string
const (
	FieldTypeString FieldType = "string"
	FieldTypeInt    FieldType = "int32"
	FieldTypeInt64  FieldType = "int64"
	FieldTypeFloat  FieldType = "float64"
	FieldTypeBool   FieldType = "bool"
	FieldTypeTime   FieldType = "time"
	FieldTypeByte   FieldType = "[]byte"
	FieldTypeJSON   FieldType = "json"
)

type Index

type Index struct {
	Type    IndexType
	Columns []IndexColumn
	Unique  bool
	Name    string
}

func (Index) FieldNames

func (i Index) FieldNames() []string

type IndexColumn

type IndexColumn struct {
	Name string
	Desc bool // false = ASC (default), true = DESC
}

type IndexType

type IndexType string
const (
	IndexPrimary IndexType = "primary"
	IndexRegular IndexType = "index"
)

type Query

type Query struct {
	Type      QueryType
	Fields    []string
	Filters   []QueryFilter
	Count     bool
	OrderBy   string
	Name      string // custom query name; empty means auto-generated
	Comment   string
	Contracts []Contract
}

func (Query) HasContract added in v0.0.3

func (q Query) HasContract(contractType ContractType) bool

func (Query) IsWrite added in v0.0.3

func (q Query) IsWrite() bool

type QueryFilter

type QueryFilter struct {
	Type     QueryFilterType
	Field    string
	Optional bool
}

type QueryFilterType

type QueryFilterType string
const (
	QueryFilterRange  QueryFilterType = "range"
	QueryFilterSearch QueryFilterType = "search"
	QueryFilterEq     QueryFilterType = "eq"
)

type QueryType

type QueryType string
const (
	QueryCreate     QueryType = "create"
	QueryCreateBulk QueryType = "create_bulk"
	QueryUpdate     QueryType = "update"
	QueryDelete     QueryType = "delete"
	QueryDeleteAll  QueryType = "delete_all"
	QueryGetBy      QueryType = "get_by"
	QueryListBy     QueryType = "list_by"
	QueryListAll    QueryType = "list_all"
)

type SQLDialect

type SQLDialect string
const (
	MySQL      SQLDialect = "mysql"
	SQLite     SQLDialect = "sqlite"
	PostgreSQL SQLDialect = "postgresql"
)

type Schema

type Schema struct {
	Entities []Entity
}

Jump to

Keyboard shortcuts

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