Documentation
¶
Index ¶
Constants ¶
View Source
const ConnectionTemplate = `` /* 598-byte string literal not displayed */
ConnectionTemplate is the template for the connection functions. This is included in the init template.
View Source
const ErrorsTemplate = `` /* 460-byte string literal not displayed */
ErrorsTemplate is the template for the errors. This is included in the init template.
View Source
const InitStatementTemplate = `` /* 496-byte string literal not displayed */
InitStatementTemplate is the template for the init functions.
View Source
const OptionsTemplate = `` /* 9294-byte string literal not displayed */
View Source
const SingleRepeatedTypesTemplate = `` /* 1555-byte string literal not displayed */
View Source
const StorageTemplate = `` /* 3783-byte string literal not displayed */
StorageTemplate is the template for the storage functions. This is included in the init template.
View Source
const StructureTemplate = `
// {{ structureName }} is a struct for the "{{ tableName }}" table.
type {{ structureName }} struct {
{{ range $field := fields }}
{{ $field | fieldName }} {{ $field | fieldType }}{{if not ($field | isRelation) }}` + "" + `{{end}}{{end}}
}
// TableName returns the table name.
func (t *{{ structureName }}) TableName() string {
return "{{ tableName }}"
}
// ScanRow scans a row into a {{ structureName }}.
func (t *{{ structureName }}) ScanRow(row driver.Row) error {
return row.Scan(
{{- range $field := fields }}
{{- if not ($field | isRelation) }}
&t.{{ $field | fieldName }},
{{- end }}
{{- end }}
)
}`
View Source
const TableBatchCreateMethodTemplate = `` /* 1908-byte string literal not displayed */
View Source
const TableConditionFilters = `` /* 10354-byte string literal not displayed */
View Source
const TableConditionsTemplate = `` /* 12985-byte string literal not displayed */
View Source
const TableCountMethodTemplate = `
`
View Source
const TableCreateAsyncMethodTemplate = `` /* 2860-byte string literal not displayed */
View Source
const TableCreateMethodTemplate = `` /* 2770-byte string literal not displayed */
View Source
const TableDeleteMethodTemplate = ``
View Source
const TableFindManyMethodTemplate = `` /* 2667-byte string literal not displayed */
View Source
const TableFindOneMethodTemplate = `` /* 524-byte string literal not displayed */
View Source
const TableFindWithPaginationMethodTemplate = ``
View Source
const TableGetByIDMethodTemplate = ``
View Source
const TableLockMethodTemplate = ``
View Source
const TableOriginalBatchCreateMethodTemplate = `` /* 2311-byte string literal not displayed */
View Source
const TableRawQueryMethodTemplate = `` /* 1149-byte string literal not displayed */
View Source
const TableStorageTemplate = `` /* 11815-byte string literal not displayed */
View Source
const TableTemplate = `` /* 595-byte string literal not displayed */
View Source
const TableUpdateMethodTemplate = ``
View Source
const TransactionManagerTemplate = `
// QueryExecer is an interface that can execute queries.
type QueryExecer interface {
driver.Conn
}
`
View Source
const TypesTemplate = `
// NullableJSON represents a JSON field that can be null.
type NullableJSON[T any] struct {
Data T
Valid bool // Valid is true if the field is not NULL
}
// NewNullableJSON creates a new NullableJSON with a value.
func NewNullableJSON[T any](v T) NullableJSON[T] {
return NullableJSON[T]{Data: v, Valid: true}
}
// Scan implements the sql.Scanner interface.
func (n *NullableJSON[T]) Scan(value interface{}) error {
if value == nil {
n.Valid = false
return nil
}
str, ok := value.(string)
if !ok {
return fmt.Errorf("failed to convert value to string")
}
if err := json.Unmarshal([]byte(str), &n.Data); err != nil {
n.Valid = false
return fmt.Errorf("failed to unmarshal json: %w", err)
}
n.Valid = true
return nil
}
// Value converts NullableJSON to a string representation for ClickHouse.
func (n *NullableJSON[T]) Value() (string, error) {
if !n.Valid {
return "", nil
}
bytes, err := json.Marshal(n.Data)
if err != nil {
return "", fmt.Errorf("failed to marshal json: %w", err)
}
return string(bytes), nil
}
// ValueOrZero returns the value if valid, otherwise returns the zero value of type T.
func (n NullableJSON[T]) ValueOrZero() T {
if !n.Valid {
var zero T
return zero
}
return n.Data
}
{{ range $key, $field := nestedMessages }}
// {{ $key }} is a JSON type nested in another message.
type {{ $field.StructureName }} struct {
{{- range $nestedField := $field.Descriptor.GetField }}
{{ $nestedField | fieldName }} {{ $nestedField | fieldType }}` + " `json:\"{{ $nestedField | sourceName }}\"`" + `
{{- end }}
}
// Scan implements the sql.Scanner interface for JSON.
func (m *{{ $field.StructureName }}) Scan(src interface{}) error {
if str, ok := src.(string); ok {
return json.Unmarshal([]byte(str), m)
}
return fmt.Errorf("can't convert %T to string", src)
}
// Value converts the struct to a JSON string.
func (m *{{ $field.StructureName }}) Value() (string, error) {
if m == nil {
m = &{{ $field.StructureName }}{}
}
bytes, err := json.Marshal(m)
if err != nil {
return "", fmt.Errorf("failed to marshal json: %w", err)
}
return string(bytes), nil
}
{{ end }}`
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.