sq/libsq/ast/sqlbuilder/sqlbuilder.go
Neil O'Toole 98e91bae51
Bunch of linting issues (#96)
* linting

* linting

* linting

* linting

* linting

* cleaned up readme trailing newlines
2021-09-12 16:14:30 -06:00

56 lines
1.4 KiB
Go

// Package sqlbuilder contains functionality for building SQL from
// the AST.
package sqlbuilder
import (
"github.com/neilotoole/sq/libsq/ast"
)
// FragmentBuilder renders driver-specific SQL fragments.
type FragmentBuilder interface {
// FromTable renders a FROM table fragment.
FromTable(tblSel *ast.TblSelector) (string, error)
// SelectCols renders a column names/expression fragment.
SelectCols(cols []ast.ColExpr) (string, error)
// SelectAll renders a SELECT * fragment.
SelectAll(tblSel *ast.TblSelector) (string, error)
// Range renders a row range fragment.
Range(rr *ast.RowRange) (string, error)
// Join renders a join fragment.
Join(fnJoin *ast.Join) (string, error)
// Function renders a function fragment.
Function(fn *ast.Func) (string, error)
// Where renders a WHERE fragment.
Where(where *ast.Where) (string, error)
// Expr renders an expression fragment.
Expr(expr *ast.Expr) (string, error)
// Operator renders an operator fragment.
Operator(op *ast.Operator) (string, error)
}
// QueryBuilder provides an abstraction for building a SQL query.
type QueryBuilder interface {
// SetSelect sets the columns to select.
SetSelect(cols string)
// SetFrom sets the FROM clause.
SetFrom(from string)
// SetWhere sets the WHERE clause.
SetWhere(where string)
// SetRange sets the range clause.
SetRange(rng string)
// SQL renders the SQL query.
SQL() (string, error)
}