sql

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package sql provides facilities for mapping a pathbuilder and odbc importer to sql statements.

Index

Constants

This section is empty.

Variables

View Source
var MARSHAL_COMMENT_PREFIX = `` /* 288-byte string literal not displayed */

MARSHAL_COMMENT_PREFIX is a comment string that explains the syntax of a selector jsonc file.

The comment is dynamically populated, and will always contain examples for every known selector type.

View Source
var RUNE_QUOTE = '`'

Functions

func ForTable

func ForTable(table odbc.Table) string

ForTable generates an sql statement used by the importer with the given table

func MarshalSelector

func MarshalSelector(selector Selector) (string, error)

MarshalSelector marshals the given Selector into a string

Types

type Builder

type Builder map[string]TableBuilder

Builder provides a correspondance between bundle ids and TableBuilder.

New values should be created using make(). The zero value does not cause panic(), but can not hold and correspondences

func NewBuilder

func NewBuilder(pb pathbuilder.Pathbuilder) Builder

NewBuilder creates a new builder from a pathbuilder.

Each bundle in the pathbuilder will correspond to a new TableBuilder. See BundleBuilder for details.

func (Builder) Apply

func (b Builder) Apply(server *odbc.Server) error

Apply updates the provided ODBC instance tables with correspondences provided within this Builder. Tables that do not have any correspondance will be removed from server.

type ColumnSelector

type ColumnSelector struct {
	Column Identifier
}

ColumnSelector is a selector that selects a single column from the main sql table

type Identifier

type Identifier string

Identifier represents an SQL Identifier

An identifier can be quoted or escaped, see the Quote() and Escape() methods. Both operations make the identifier safe to use directly in SQL strings.

Identifier implements fmt.Formatter, see Format.

func TokenizeIdentifiers

func TokenizeIdentifiers(value string) (results []Identifier)

TokenizeIdentifiers is like strings.Split, except that instead of splitting only by spaces uses GobbleIdentifiers instead

func (Identifier) Escape

func (identifier Identifier) Escape() (escaped string, ok bool)

Escape escapes this identifier into a string safe for usage within a MariaDB query. Escape performs quoting of the identifier only if necessary.

If value is not a valid identifier (neither quoted nor unquoted), returns it unchanged and ok=false.

func (Identifier) Escaped

func (identifier Identifier) Escaped() string

Escaped is is like Escape, but only returns the first value

func (Identifier) Format

func (identifier Identifier) Format(f fmt.State, verb rune)

Format implements the fmt.Formatter interface The 's' verb escapes the identifier, the 'q' verb quotes the identifier.

func (Identifier) Quote

func (identifier Identifier) Quote() (quoted string, ok bool)

func (Identifier) Quoted

func (identifier Identifier) Quoted() string

Quoted is like Quote, but returns only the first value

type IdentifierFactory

type IdentifierFactory Identifier

IdentifierFactory can generate identifiers with a prefix

func (IdentifierFactory) Get

func (idf IdentifierFactory) Get(value string) Identifier

Get gets an identifier from this factory

type JoinSelector

type JoinSelector struct {
	Column Identifier

	Table Identifier

	OurKey   Identifier
	TheirKey Identifier
}

JoinSelector selects Column from a secondary Table using a (left) join on equality of OurKey and TheirKey

type Many2ManySelector

type Many2ManySelector struct {
	Column Identifier
	Table  Identifier

	Through Identifier

	TheirKey        Identifier
	TheirThroughKey Identifier
	OurThroughKey   Identifier
	OurKey          Identifier
}

Many2ManySelector selects a many2many relation.

type Selector

type Selector interface {
	// contains filtered or unexported methods
}

Selector provides means of selecting a value from an sql table.

Selectors are intentionally intransparent to the caller; they should only be accessed using the MarshalSelector and UnmarshalSelector methods.

Internally any selector type takes a pointer receiver.

func UnmarshalSelector

func UnmarshalSelector(data string) (selector Selector, err error)

UnmarshalSelector unmarshals a selector from a string

type TableBuilder

type TableBuilder struct {
	TableName string // name of the table to use
	ID        string // name of the column for ID
	Disinct   bool   // should we select distinct fields?
	Order     int    // order of different tables

	Fields map[string]Selector // Selectors for each bundle
}

TableBuilder provides facitilies to create sql statements for ODBC tables.

func NewTableBuilder

func NewTableBuilder(bundle pathbuilder.Bundle) TableBuilder

NewTableBuilder creates a new default TableBuilder for the given bundle.

Each enabled field in the bundle will have a corresponding selector. Any further details are an implementation detail, and should not be relied upon by the caller.

func (TableBuilder) Apply

func (tb TableBuilder) Apply(table *odbc.Table) error

Apply updates the provided ODBC table with correspondences provided within this Builder.

Bundles inside a table that do not have a corresponding sql in this TableBuilder will be removed.

func (TableBuilder) Build

func (tb TableBuilder) Build() (selectS, appendS string, err error)

Build builds two sql strings for usage within the odbc importer for this table.

The select statement contains a list of fields to be selected. The appen statement represents an abitrary sql statement that should be appened to the sql statement as a whole.

Either SQL statement is escaped and can be safely inserted inside an sql statement.

func (TableBuilder) MarshalJSON

func (tb TableBuilder) MarshalJSON() ([]byte, error)

MarshalJSON marshals the given table builder as JSON

func (*TableBuilder) UnmarshalJSON

func (tb *TableBuilder) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the provided data into this

Jump to

Keyboard shortcuts

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