fiqlsqladapter

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2023 License: BSD-2-Clause Imports: 7 Imported by: 1

README

fiql-sql-adapter

Go Report Card Go GoDoc reference example License

golang fiql2sql adapter - early work in progress

Getting Started

Do not use this as of now, it's still being actively developed.

If you wanna peek at the project feel free to do so, but expect it to break.

(back to top)

Why

fiql-sql-adapter exists to have a common and in GET requests useable query possibility. Its main goal is to free you from writing custom search queries for classic CRUD applications.

(back to top)

Featurelist

This list represents the features I would like it to have once its done.

  • safe FIQL parsing
  • defining a fiql-to-table mapping manually
  • defining a fiql-to-table mapping by struct tags
  • sophisticated type checks (as of now its rather crude with minimal type support)
  • value converters to convert fiql supplied arguments to the corresponding sql parameter
  • join and computed column handling - this is tricky and needs some more thought [^1]

[^1]: Right now this could be archived with a view but that's not what I am after.

Contributing

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue for further questions or recommendations.

(back to top)

License

Distributed under the BSD-2-Clause license. See LICENSE.txt for more information.

(back to top)

Documentation

Index

Constants

View Source
const (
	DialectMariaDB  = "maria"
	DialectMySQL    = "mysql"
	DialectMSSL     = "mssql"
	DialectSQLite   = "sqlite3"
	DialectPostgres = "postgres"
)

Dialect constants

Variables

This section is empty.

Functions

func WithDialect

func WithDialect(dialect string) func(*Adapter)

WithDialect configures which dialect to be used

func WithDialectMSSQL

func WithDialectMSSQL() func(*Adapter)

WithDialectMSSQL configures MSSQL delimiters and params

func WithDialectMariaDB

func WithDialectMariaDB() func(*Adapter)

WithDialectMariaDB configures MariaDB / MySql delimiters and params

func WithDialectPostgres

func WithDialectPostgres() func(*Adapter)

WithDialectPostgres configures Postgres delimiters and params

func WithDialectSQL92

func WithDialectSQL92() func(*Adapter)

WithDialectSQL92 means column delimiter is " and parameters are ?

func WithDialectSQL92NoDelimiter

func WithDialectSQL92NoDelimiter() func(*Adapter)

WithDialectSQL92NoDelimiter means no column delimiter is used and parameters are ?

func WithDialectSQLite

func WithDialectSQLite() func(*Adapter)

WithDialectSQLite configures SQLite delimiters and params

func WithTableName added in v0.0.4

func WithTableName(tableName string) func(*Adapter)

WithTableName creates an adapter that prefixes all columns with the given table name if a struct tag defines a table prefix it will take precedence over the supplied adapter table name

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter adapter is a fiql2sql adapter one adapter per table is needed unless all tables carry the same columns - but i would not recommend sharing adapters for multiple tables

func NewAdapter

func NewAdapter(mapping FieldMapping, options ...func(*Adapter)) *Adapter

NewAdapter returns a new fiql adapter for the given field mapping use the MappingBuilder to create field mapping

func NewAdapterFor

func NewAdapterFor(typeDef interface{}, options ...func(*Adapter)) *Adapter

NewAdapterFor creates a new adapter from struct tags of the typeDef argument

func (*Adapter) OrderBy

func (a *Adapter) OrderBy(query string) (*OrderByClause, error)

OrderBy generates a order by clause from a given query this is no fiql but rather the format ([+|-|])ALIAS[;([+|-|])ALIAS]*

func (*Adapter) Update added in v0.0.5

func (a *Adapter) Update(options ...func(*Adapter))

Update updates the given adapters supplied options this may be used to change dialect or other specfics with an already instanced adapater

func (*Adapter) Where

func (a *Adapter) Where(query string) (*WherePredicate, error)

Where generates a where predicate from a given fiql query

type Field

type Field struct {
	Db          string
	Alias       string
	Type        reflect.Type
	TablePrefix string
}

Field is a fiql field to database column mapping

type FieldMapping

type FieldMapping map[string]Field

FieldMapping is a table mapping of fields

type MappingBuilder

type MappingBuilder struct {
	// contains filtered or unexported fields
}

MappingBuilder helps build FieldMappings manually if no struct tags are used

func NewMappingBuilder

func NewMappingBuilder() *MappingBuilder

NewMappingBuilder returns a new instance of a MappingBuilder

func (*MappingBuilder) AddDateMapping

func (b *MappingBuilder) AddDateMapping(column, selector string) *MappingBuilder

AddDateMapping adds a column to fiql selector mapping for a date(time) column

func (*MappingBuilder) AddFloatMapping

func (b *MappingBuilder) AddFloatMapping(column, selector string) *MappingBuilder

AddFloatMapping adds a column to fiql selector mapping for a decimal column

func (*MappingBuilder) AddIntMapping

func (b *MappingBuilder) AddIntMapping(column, selector string) *MappingBuilder

AddIntMapping adds a column to fiql selector mapping for a numeric column

func (*MappingBuilder) AddStringMapping

func (b *MappingBuilder) AddStringMapping(column, selector string) *MappingBuilder

AddStringMapping adds a column to fiql selector mapping for a string column

func (*MappingBuilder) Build

func (b *MappingBuilder) Build() FieldMapping

Build returns the generated

type OrderByClause

type OrderByClause struct {
	// contains filtered or unexported fields
}

OrderByClause represents a order by clause without the order by keyword

func (*OrderByClause) Query added in v0.0.5

func (o *OrderByClause) Query() (string, []any)

Query satisfies querier interface from ent https://pkg.go.dev/entgo.io/ent@v0.12.4/dialect/sql#Querier

func (*OrderByClause) Sql

func (o *OrderByClause) Sql() string

Sql returns the underlying sql string

func (*OrderByClause) String

func (o *OrderByClause) String() string

String simply returns the query string

func (*OrderByClause) ToSql

func (o *OrderByClause) ToSql() (string, []interface{}, error)

ToSql returns the query string and the parameters satisfies sqlizer https://pkg.go.dev/github.com/masterminds/squirrel#Sqlizer

type WherePredicate

type WherePredicate struct {
	// contains filtered or unexported fields
}

WherePredicate holds the content of a where predicate it will always be wrapped in outter most braces to avoid issues with OR chaining leading to unwated results it does not contain the WHERE keyword

func (*WherePredicate) Parameters

func (w *WherePredicate) Parameters() []interface{}

Parameters return the underlying parameters

func (*WherePredicate) Query

func (w *WherePredicate) Query() (string, []any)

Query satisfies querier interface from ent https://pkg.go.dev/entgo.io/ent@v0.12.4/dialect/sql#Querier

func (*WherePredicate) Sql

func (w *WherePredicate) Sql() string

Sql returns the underlying sql string

func (*WherePredicate) String

func (w *WherePredicate) String() string

String simply returns the query string and paremeters

func (*WherePredicate) ToSql

func (w *WherePredicate) ToSql() (string, []interface{}, error)

ToSql returns the query string and the parameters satisfies sqlizer https://pkg.go.dev/github.com/masterminds/squirrel#Sqlizer

Jump to

Keyboard shortcuts

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