Documentation
¶
Overview ¶
Fully persistent data structures. A persistent data structure is a data structure that always preserves the previous version of itself when it is modified. Such data structures are effectively immutable, as their operations do not update the structure in-place, but instead always yield a new structure.
Persistent data structures typically share structure among themselves. This allows operations to avoid copying the entire data structure.
Package n1qlizer provides a fluent Couchbase N1QL query generator.
It is inspired by github.com/Masterminds/squirrel
Index ¶
- Variables
- func Append[T any, V any](builder T, name string, vs ...V) T
- func DebugN1qlizer(s N1qlizer) string
- func Extend[T any, V any](builder T, name string, vs []V) T
- func ExtendValues[T any](builder T, name string, vs any) T
- func Get[T any](builder T, name string) (any, bool)
- func GetBuilderStructType(builderType reflect.Type) reflect.Type
- func GetMap[T any](builder T) map[string]any
- func GetStruct[T any](builder T) any
- func GetStructLike[T any, S any](builder T, strct S) S
- func JSONField(fieldPath string) string
- func NewBuilderStruct(builderType reflect.Type) *reflect.Value
- func Register(builderProto any, structProto any) any
- func RegisterBuilder(builderProto any, structProto any) any
- func RegisterBuilderType(builderType reflect.Type, structType reflect.Type) *reflect.Value
- func RegisterType(builderType reflect.Type, structType reflect.Type) *reflect.Value
- func Remove[T any](builder T, name string) T
- func Set[T any, V any](builder T, name string, v V) T
- type AnalyticsSelectBuilder
- func (b AnalyticsSelectBuilder) Column(column any, args ...any) AnalyticsSelectBuilder
- func (b AnalyticsSelectBuilder) Columns(columns ...string) AnalyticsSelectBuilder
- func (b AnalyticsSelectBuilder) Execute() (QueryResult, error)
- func (b AnalyticsSelectBuilder) ExecuteContext(ctx context.Context) (QueryResult, error)
- func (b AnalyticsSelectBuilder) From(from string) AnalyticsSelectBuilder
- func (b AnalyticsSelectBuilder) GroupBy(groupBys ...string) AnalyticsSelectBuilder
- func (b AnalyticsSelectBuilder) Having(pred any, rest ...any) AnalyticsSelectBuilder
- func (b AnalyticsSelectBuilder) Let(variable string, value any) AnalyticsSelectBuilder
- func (b AnalyticsSelectBuilder) Limit(limit uint64) AnalyticsSelectBuilder
- func (b AnalyticsSelectBuilder) MustN1ql() (string, []any)
- func (b AnalyticsSelectBuilder) Offset(offset uint64) AnalyticsSelectBuilder
- func (b AnalyticsSelectBuilder) OrderBy(orderBys ...string) AnalyticsSelectBuilder
- func (b AnalyticsSelectBuilder) PlaceholderFormat(f PlaceholderFormat) AnalyticsSelectBuilder
- func (b AnalyticsSelectBuilder) RunWith(runner QueryRunner) AnalyticsSelectBuilder
- func (b AnalyticsSelectBuilder) RunWithContext(runner QueryRunnerContext) AnalyticsSelectBuilder
- func (b AnalyticsSelectBuilder) ToN1ql() (string, []any, error)
- func (b AnalyticsSelectBuilder) Where(pred any, args ...any) AnalyticsSelectBuilder
- func (b AnalyticsSelectBuilder) Window(windowClause string) AnalyticsSelectBuilder
- type And
- type Any
- type Builder
- type CaseBuilder
- type DeleteBuilder
- func (b DeleteBuilder) Execute() (QueryResult, error)
- func (b DeleteBuilder) ExecuteContext(ctx context.Context) (QueryResult, error)
- func (b DeleteBuilder) From(from string) DeleteBuilder
- func (b DeleteBuilder) Limit(limit uint64) DeleteBuilder
- func (b DeleteBuilder) MustN1ql() (string, []any)
- func (b DeleteBuilder) Offset(offset uint64) DeleteBuilder
- func (b DeleteBuilder) PlaceholderFormat(f PlaceholderFormat) DeleteBuilder
- func (b DeleteBuilder) Prefix(sql string, args ...any) DeleteBuilder
- func (b DeleteBuilder) PrefixExpr(expr N1qlizer) DeleteBuilder
- func (b DeleteBuilder) RunWith(runner QueryRunner) DeleteBuilder
- func (b DeleteBuilder) RunWithContext(runner QueryRunnerContext) DeleteBuilder
- func (b DeleteBuilder) Suffix(sql string, args ...any) DeleteBuilder
- func (b DeleteBuilder) SuffixExpr(expr N1qlizer) DeleteBuilder
- func (b DeleteBuilder) ToN1ql() (string, []any, error)
- func (b DeleteBuilder) UseKeys(keys string) DeleteBuilder
- func (b DeleteBuilder) Where(pred any, args ...any) DeleteBuilder
- type Eq
- type FTSSearchOptions
- type GenericList
- type GenericMap
- type Gt
- type Gte
- type InsertBuilder
- func (b InsertBuilder) Columns(columns ...string) InsertBuilder
- func (b InsertBuilder) Execute() (QueryResult, error)
- func (b InsertBuilder) ExecuteContext(ctx context.Context) (QueryResult, error)
- func (b InsertBuilder) Into(into string) InsertBuilder
- func (b InsertBuilder) MustN1ql() (string, []any)
- func (b InsertBuilder) Options(options ...string) InsertBuilder
- func (b InsertBuilder) PlaceholderFormat(f PlaceholderFormat) InsertBuilder
- func (b InsertBuilder) Prefix(sql string, args ...any) InsertBuilder
- func (b InsertBuilder) PrefixExpr(expr N1qlizer) InsertBuilder
- func (b InsertBuilder) RunWith(runner QueryRunner) InsertBuilder
- func (b InsertBuilder) RunWithContext(runner QueryRunnerContext) InsertBuilder
- func (b InsertBuilder) SetMap(clauses map[string]any) InsertBuilder
- func (b InsertBuilder) Suffix(sql string, args ...any) InsertBuilder
- func (b InsertBuilder) SuffixExpr(expr N1qlizer) InsertBuilder
- func (b InsertBuilder) ToN1ql() (string, []any, error)
- func (b InsertBuilder) Values(values ...any) InsertBuilder
- type JSONDocument
- type LeftNestClause
- type LeftUnnestClause
- type List
- type Lt
- type Lte
- type Map
- type N1qlizer
- func Alias(expr N1qlizer, alias string) N1qlizer
- func ArrayAvg(arr string) N1qlizer
- func ArrayCount(arr string) N1qlizer
- func ArrayFilter(arr, variable, condition string) N1qlizer
- func ArrayFlatten(arr string) N1qlizer
- func ArrayMax(arr string) N1qlizer
- func ArrayMin(arr string) N1qlizer
- func ArraySum(arr string) N1qlizer
- func Expr(sql any, args ...any) N1qlizer
- func FTSConjunction(expressions ...N1qlizer) N1qlizer
- func FTSDisjunction(expressions ...N1qlizer) N1qlizer
- func FTSMatch(query string, options ...FTSSearchOptions) N1qlizer
- func FTSPhraseMatch(query string, options ...FTSSearchOptions) N1qlizer
- func FTSPrefixMatch(prefix string, options ...FTSSearchOptions) N1qlizer
- func FTSRangeMatch(field string, min, max interface{}, options ...FTSSearchOptions) N1qlizer
- func FTSSearchService(indexName, query string, options ...interface{}) N1qlizer
- func FTSWildcardMatch(pattern string, options ...FTSSearchOptions) N1qlizer
- func JSONArray(values ...any) N1qlizer
- func JSONArrayContains(field string, value any) N1qlizer
- func JSONObject(keyValuePairs ...any) N1qlizer
- func ObjectNames(obj string) N1qlizer
- func ObjectPairs(obj string) N1qlizer
- func ObjectPut(obj, fieldName, value string) N1qlizer
- func ObjectRemove(obj string, fields ...string) N1qlizer
- func ObjectValues(obj string) N1qlizer
- func SubDocument(document any, path ...string) N1qlizer
- type NestClause
- type NestedField
- type NotEq
- type Or
- type PlaceholderFormat
- type QueryExecutor
- type QueryExecutorContext
- type QueryResult
- type QueryRunner
- type QueryRunnerContext
- type SelectBuilder
- func (b SelectBuilder) Column(column any, args ...any) SelectBuilder
- func (b SelectBuilder) Columns(columns ...string) SelectBuilder
- func (b SelectBuilder) Distinct() SelectBuilder
- func (b SelectBuilder) Execute() (QueryResult, error)
- func (b SelectBuilder) ExecuteContext(ctx context.Context) (QueryResult, error)
- func (b SelectBuilder) From(from string) SelectBuilder
- func (b SelectBuilder) FromSelect(from SelectBuilder, alias string) SelectBuilder
- func (b SelectBuilder) GroupBy(groupBys ...string) SelectBuilder
- func (b SelectBuilder) Having(pred any, rest ...any) SelectBuilder
- func (b SelectBuilder) InnerJoin(join string, rest ...any) SelectBuilder
- func (b SelectBuilder) Join(join string, rest ...any) SelectBuilder
- func (b SelectBuilder) JoinClause(join string, args ...any) SelectBuilder
- func (b SelectBuilder) LeftJoin(join string, rest ...any) SelectBuilder
- func (b SelectBuilder) LeftNest(bucket string) SelectBuilder
- func (b SelectBuilder) LeftNestClause(nest LeftNestClause) SelectBuilder
- func (b SelectBuilder) LeftUnnest(path string) SelectBuilder
- func (b SelectBuilder) LeftUnnestClause(unnest LeftUnnestClause) SelectBuilder
- func (b SelectBuilder) Limit(limit uint64) SelectBuilder
- func (b SelectBuilder) MustN1ql() (string, []any)
- func (b SelectBuilder) Nest(bucket string) SelectBuilder
- func (b SelectBuilder) NestClause(nest NestClause) SelectBuilder
- func (b SelectBuilder) Offset(offset uint64) SelectBuilder
- func (b SelectBuilder) Options(options ...string) SelectBuilder
- func (b SelectBuilder) OrderBy(orderBys ...string) SelectBuilder
- func (b SelectBuilder) OrderByClause(pred any, args ...any) SelectBuilder
- func (b SelectBuilder) PlaceholderFormat(f PlaceholderFormat) SelectBuilder
- func (b SelectBuilder) Prefix(sql string, args ...any) SelectBuilder
- func (b SelectBuilder) PrefixExpr(expr N1qlizer) SelectBuilder
- func (b SelectBuilder) RightJoin(join string, rest ...any) SelectBuilder
- func (b SelectBuilder) RunWith(runner QueryRunner) SelectBuilder
- func (b SelectBuilder) RunWithContext(runner QueryRunnerContext) SelectBuilder
- func (b SelectBuilder) Suffix(sql string, args ...any) SelectBuilder
- func (b SelectBuilder) SuffixExpr(expr N1qlizer) SelectBuilder
- func (b SelectBuilder) ToN1ql() (string, []any, error)
- func (b SelectBuilder) Unnest(path string) SelectBuilder
- func (b SelectBuilder) UnnestClause(unnest UnnestClause) SelectBuilder
- func (b SelectBuilder) UseKeys(keys string) SelectBuilder
- func (b SelectBuilder) Where(pred any, args ...any) SelectBuilder
- func (b SelectBuilder) WithSearch(search N1qlizer) SelectBuilder
- type StatementBuilderType
- func (b StatementBuilderType) AnalyticsSelect(columns ...string) AnalyticsSelectBuilder
- func (b StatementBuilderType) Delete(from string) DeleteBuilder
- func (b StatementBuilderType) Insert(into string) InsertBuilder
- func (b StatementBuilderType) PlaceholderFormat(f PlaceholderFormat) StatementBuilderType
- func (b StatementBuilderType) RunWith(runner QueryRunner) StatementBuilderType
- func (b StatementBuilderType) RunWithContext(runner QueryRunnerContext) StatementBuilderType
- func (b StatementBuilderType) Select(columns ...string) SelectBuilder
- func (b StatementBuilderType) Update(table string) UpdateBuilder
- func (b StatementBuilderType) Upsert(into string) UpsertBuilder
- type StdCb
- type StdCbCtx
- type UnnestClause
- type UpdateBuilder
- func (b UpdateBuilder) Execute() (QueryResult, error)
- func (b UpdateBuilder) ExecuteContext(ctx context.Context) (QueryResult, error)
- func (b UpdateBuilder) Limit(limit uint64) UpdateBuilder
- func (b UpdateBuilder) MustN1ql() (string, []any)
- func (b UpdateBuilder) Offset(offset uint64) UpdateBuilder
- func (b UpdateBuilder) PlaceholderFormat(f PlaceholderFormat) UpdateBuilder
- func (b UpdateBuilder) Prefix(sql string, args ...any) UpdateBuilder
- func (b UpdateBuilder) PrefixExpr(expr N1qlizer) UpdateBuilder
- func (b UpdateBuilder) RunWith(runner QueryRunner) UpdateBuilder
- func (b UpdateBuilder) RunWithContext(runner QueryRunnerContext) UpdateBuilder
- func (b UpdateBuilder) Set(column string, value any) UpdateBuilder
- func (b UpdateBuilder) SetMap(clauses map[string]any) UpdateBuilder
- func (b UpdateBuilder) Suffix(sql string, args ...any) UpdateBuilder
- func (b UpdateBuilder) SuffixExpr(expr N1qlizer) UpdateBuilder
- func (b UpdateBuilder) Table(table string) UpdateBuilder
- func (b UpdateBuilder) ToN1ql() (string, []any, error)
- func (b UpdateBuilder) UseKeys(keys string) UpdateBuilder
- func (b UpdateBuilder) Where(pred any, args ...any) UpdateBuilder
- type UpsertBuilder
- func (b UpsertBuilder) Columns(columns ...string) UpsertBuilder
- func (b UpsertBuilder) Document(key string, value any) UpsertBuilder
- func (b UpsertBuilder) Execute() (QueryResult, error)
- func (b UpsertBuilder) ExecuteContext(ctx context.Context) (QueryResult, error)
- func (b UpsertBuilder) Into(into string) UpsertBuilder
- func (b UpsertBuilder) MustN1ql() (string, []any)
- func (b UpsertBuilder) Options(options ...string) UpsertBuilder
- func (b UpsertBuilder) PlaceholderFormat(f PlaceholderFormat) UpsertBuilder
- func (b UpsertBuilder) Prefix(sql string, args ...any) UpsertBuilder
- func (b UpsertBuilder) PrefixExpr(expr N1qlizer) UpsertBuilder
- func (b UpsertBuilder) RunWith(runner QueryRunner) UpsertBuilder
- func (b UpsertBuilder) RunWithContext(runner QueryRunnerContext) UpsertBuilder
- func (b UpsertBuilder) SetMap(clauses map[string]any) UpsertBuilder
- func (b UpsertBuilder) Suffix(sql string, args ...any) UpsertBuilder
- func (b UpsertBuilder) SuffixExpr(expr N1qlizer) UpsertBuilder
- func (b UpsertBuilder) ToN1ql() (string, []any, error)
- func (b UpsertBuilder) Values(values ...any) UpsertBuilder
- type UseIndex
Constants ¶
This section is empty.
Variables ¶
var ( // BuilderTypes stores the global registry of Builder types mapped to their corresponding struct types BuilderTypes = make(map[reflect.Type]reflect.Type) // BuilderMux provides thread-safe access to the BuilderTypes map BuilderMux sync.RWMutex )
var Dollar = dollarFormat{}
Dollar is a PlaceholderFormat instance that replaces placeholders with dollar-prefixed positional placeholders (e.g. $1, $2, $3). This is the format used by Couchbase N1QL.
var (
EmptyBuilder = Builder{NewMap()}
)
var Question = questionFormat{}
StatementBuilder is a parent builder for other statement builders.
var RunnerNotQueryRunnerContext = fmt.Errorf("cannot QueryRowContext; Runner is not a QueryRunnerContext")
RunnerNotQueryRunnerContext is returned by QueryRowContext if the RunWith value doesn't implement QueryRunnerContext.
var RunnerNotSet = fmt.Errorf("cannot run; no Runner set (RunWith)")
RunnerNotSet is returned by methods that need a Runner if it isn't set.
var StatementBuilder = StatementBuilderType(EmptyBuilder).PlaceholderFormat(Question)
Functions ¶
func Append ¶
Append returns a copy of the given builder with new value(s) appended to the named list. If the value was previously unset or set with Set (even to a e.g. slice values), the new value(s) will be appended to an empty list.
func DebugN1qlizer ¶
DebugN1qlizer calls ToN1ql on s and shows the approximate N1QL to be executed
If ToN1ql returns an error, the result of this method will look like: "[ToN1ql error: %s]" or "[DebugN1qlizer error: %s]"
IMPORTANT: As its name suggests, this function should only be used for debugging. While the string result *might* be valid N1QL, this function does not try very hard to ensure it. Additionally, executing the output of this function with any untrusted user input is certainly insecure.
func Extend ¶
Extend behaves like Append, except it takes a single slice or array value which will be concatenated to the named list.
Unlike a variadic call to Append - which requires a []interface{} value - Extend accepts slices or arrays of any type.
Extend will panic if the given value is not a slice, array, or nil.
func ExtendValues ¶
ExtendValues is like Extend but allows passing any value that can be iterated using reflection. Used for backward compatibility.
func Get ¶
Get retrieves a single named value from the given builder.
If the value was set with Append or Extend, the result will be a slice of the same concrete type as was appended to the list.
Get will panic when getting a key that was set with Append or Extend and the types of values in the list don't match. Get will also panic if a value was set with Set using a type derived from a registered struct's exported field and the value set on the Builder is not assignable to the field.
func GetBuilderStructType ¶
GetBuilderStructType returns the registered struct type for a given builder type
func GetMap ¶
GetMap returns a copy of the builder's underlying map of values.
If any values were appended with Append or Extend, the value in the map will be the equivalent slice or array.
See notes on Get regarding returned slices.
func GetStruct ¶
GetStruct returns a new value with the same type as a struct registered for the given Builder type with field values taken from the builder.
GetStruct will panic if any of these "exported" values are not assignable to their corresponding struct fields.
func GetStructLike ¶
GetStructLike will panic if any of these "exported" values are not assignable to their corresponding struct fields.
func NewBuilderStruct ¶
NewBuilderStruct returns a new value with the same type as a struct associated with the given Builder type.
func Register ¶
Register wraps RegisterType, taking instances instead of Types.
Returns an empty instance of the registered builder type which can be used as the initial value for builder expressions. See example.
func RegisterBuilder ¶
RegisterBuilder wraps RegisterBuilderType, taking instances instead of types.
Returns an empty instance of the registered builder type, which can be used as the initial value for builder expressions. See example.
func RegisterBuilderType ¶
RegisterBuilderType registers a Builder type and its corresponding struct type. This mapping affects the type of slices returned by Get and is required for GetStruct to work.
Returns a Value containing an instance of the registered builderType.
RegisterBuilderType will panic if builderType's underlying type is not Builder or if structType's Kind is not Struct.
func RegisterType ¶
RegisterType maps the given builderType to a structType. This mapping affects the type of slices returned by Get and is required for GetStruct to work.
Returns a Value containing an empty instance of the registered builderType.
RegisterType will panic if builderType's underlying type is not Builder or if structType's Kind is not Struct.
Types ¶
type AnalyticsSelectBuilder ¶
type AnalyticsSelectBuilder Builder
AnalyticsSelectBuilder builds Couchbase Analytics SELECT statements.
func AnalyticsSelect ¶
func AnalyticsSelect(columns ...string) AnalyticsSelectBuilder
AnalyticsSelect creates a new AnalyticsSelectBuilder for Couchbase Analytics queries.
func (AnalyticsSelectBuilder) Column ¶
func (b AnalyticsSelectBuilder) Column(column any, args ...any) AnalyticsSelectBuilder
Column adds a result column to the query. Unlike Columns, Column accepts args which will be bound to placeholders in the column string, for example:
.Column("IF(n_subscribers > ?, ?, ?)", 100, "HIGH", "LOW")
func (AnalyticsSelectBuilder) Columns ¶
func (b AnalyticsSelectBuilder) Columns(columns ...string) AnalyticsSelectBuilder
Columns adds result columns to the query.
func (AnalyticsSelectBuilder) Execute ¶
func (b AnalyticsSelectBuilder) Execute() (QueryResult, error)
Execute builds and executes the query.
func (AnalyticsSelectBuilder) ExecuteContext ¶
func (b AnalyticsSelectBuilder) ExecuteContext(ctx context.Context) (QueryResult, error)
ExecuteContext builds and executes the query using the provided context.
func (AnalyticsSelectBuilder) From ¶
func (b AnalyticsSelectBuilder) From(from string) AnalyticsSelectBuilder
From sets the FROM clause of the query.
func (AnalyticsSelectBuilder) GroupBy ¶
func (b AnalyticsSelectBuilder) GroupBy(groupBys ...string) AnalyticsSelectBuilder
GroupBy adds GROUP BY expressions to the query.
func (AnalyticsSelectBuilder) Having ¶
func (b AnalyticsSelectBuilder) Having(pred any, rest ...any) AnalyticsSelectBuilder
Having adds an expression to the HAVING clause of the query.
func (AnalyticsSelectBuilder) Let ¶
func (b AnalyticsSelectBuilder) Let(variable string, value any) AnalyticsSelectBuilder
Let adds a LET binding variable to the query.
func (AnalyticsSelectBuilder) Limit ¶
func (b AnalyticsSelectBuilder) Limit(limit uint64) AnalyticsSelectBuilder
Limit sets a LIMIT clause on the query.
func (AnalyticsSelectBuilder) MustN1ql ¶
func (b AnalyticsSelectBuilder) MustN1ql() (string, []any)
MustN1ql builds the query into a N1QL string and bound args.
MustN1ql panics if there are any errors.
func (AnalyticsSelectBuilder) Offset ¶
func (b AnalyticsSelectBuilder) Offset(offset uint64) AnalyticsSelectBuilder
Offset sets an OFFSET clause on the query.
func (AnalyticsSelectBuilder) OrderBy ¶
func (b AnalyticsSelectBuilder) OrderBy(orderBys ...string) AnalyticsSelectBuilder
OrderBy adds ORDER BY expressions to the query.
func (AnalyticsSelectBuilder) PlaceholderFormat ¶
func (b AnalyticsSelectBuilder) PlaceholderFormat(f PlaceholderFormat) AnalyticsSelectBuilder
PlaceholderFormat sets PlaceholderFormat (e.g. Question or Dollar) for the query.
func (AnalyticsSelectBuilder) RunWith ¶
func (b AnalyticsSelectBuilder) RunWith(runner QueryRunner) AnalyticsSelectBuilder
RunWith sets a Runner (like a Couchbase DB connection) to be used with e.g. Execute.
func (AnalyticsSelectBuilder) RunWithContext ¶
func (b AnalyticsSelectBuilder) RunWithContext(runner QueryRunnerContext) AnalyticsSelectBuilder
RunWithContext sets a QueryRunnerContext (like a Couchbase DB connection with context methods) to be used with e.g. ExecuteContext.
func (AnalyticsSelectBuilder) ToN1ql ¶
func (b AnalyticsSelectBuilder) ToN1ql() (string, []any, error)
ToN1ql builds the query into a N1QL string and bound args.
func (AnalyticsSelectBuilder) Where ¶
func (b AnalyticsSelectBuilder) Where(pred any, args ...any) AnalyticsSelectBuilder
Where adds an expression to the WHERE clause of the query.
func (AnalyticsSelectBuilder) Window ¶
func (b AnalyticsSelectBuilder) Window(windowClause string) AnalyticsSelectBuilder
Window sets the WINDOW clause for window functions.
type Any ¶
type Any = any
Any is an alias for 'any', provided for backward compatibility. New code should use 'any' directly.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder stores a set of named values.
New types can be declared with underlying type Builder and used with the functions in this package. See example.
Instances of Builder should be treated as immutable. It is up to the implementor to ensure mutable values set on a Builder are not mutated while the Builder is in use.
type CaseBuilder ¶
type CaseBuilder interface { N1qlizer When(condition interface{}, value interface{}) CaseBuilder Else(value interface{}) CaseBuilder }
CaseBuilder builds SQL CASE expressions.
func NewCaseBuilder ¶
func NewCaseBuilder() CaseBuilder
NewCaseBuilder creates a new CaseBuilder for building CASE expressions
func NewCaseBuilderWithValue ¶
func NewCaseBuilderWithValue(value interface{}) CaseBuilder
NewCaseBuilderWithValue creates a new CaseBuilder for building CASE expressions with an initial value. e.g. "CASE a WHEN 'foo' THEN 1 WHEN 'bar' THEN 2 ELSE 3 END"
type DeleteBuilder ¶
type DeleteBuilder Builder
DeleteBuilder builds DELETE statements.
func Delete ¶
func Delete(from string) DeleteBuilder
Delete returns a new DeleteBuilder with the given table name.
See DeleteBuilder.Table.
func (DeleteBuilder) Execute ¶
func (b DeleteBuilder) Execute() (QueryResult, error)
Execute builds and executes the query.
func (DeleteBuilder) ExecuteContext ¶
func (b DeleteBuilder) ExecuteContext(ctx context.Context) (QueryResult, error)
ExecuteContext builds and executes the query with the context and runner set by RunWith.
func (DeleteBuilder) From ¶
func (b DeleteBuilder) From(from string) DeleteBuilder
From sets the table to be deleted from.
func (DeleteBuilder) Limit ¶
func (b DeleteBuilder) Limit(limit uint64) DeleteBuilder
Limit sets a LIMIT clause on the query.
func (DeleteBuilder) MustN1ql ¶
func (b DeleteBuilder) MustN1ql() (string, []any)
MustN1ql builds the query into a N1QL string and bound args.
MustN1ql panics if there are any errors.
func (DeleteBuilder) Offset ¶
func (b DeleteBuilder) Offset(offset uint64) DeleteBuilder
Offset sets an OFFSET clause on the query.
func (DeleteBuilder) PlaceholderFormat ¶
func (b DeleteBuilder) PlaceholderFormat(f PlaceholderFormat) DeleteBuilder
PlaceholderFormat sets PlaceholderFormat (e.g. Question or Dollar) for the query.
func (DeleteBuilder) Prefix ¶
func (b DeleteBuilder) Prefix(sql string, args ...any) DeleteBuilder
Prefix adds an expression to the beginning of the query
func (DeleteBuilder) PrefixExpr ¶
func (b DeleteBuilder) PrefixExpr(expr N1qlizer) DeleteBuilder
PrefixExpr adds an expression to the very beginning of the query
func (DeleteBuilder) RunWith ¶
func (b DeleteBuilder) RunWith(runner QueryRunner) DeleteBuilder
RunWith sets a Runner (like a Couchbase DB connection) to be used with e.g. Execute.
func (DeleteBuilder) RunWithContext ¶
func (b DeleteBuilder) RunWithContext(runner QueryRunnerContext) DeleteBuilder
RunWithContext sets a Runner (like a Couchbase DB connection with Context support) to be used with e.g. ExecuteContext.
func (DeleteBuilder) Suffix ¶
func (b DeleteBuilder) Suffix(sql string, args ...any) DeleteBuilder
Suffix adds an expression to the end of the query.
func (DeleteBuilder) SuffixExpr ¶
func (b DeleteBuilder) SuffixExpr(expr N1qlizer) DeleteBuilder
SuffixExpr adds an expression to the end of the query.
func (DeleteBuilder) ToN1ql ¶
func (b DeleteBuilder) ToN1ql() (string, []any, error)
ToN1ql builds the query into a N1QL string and bound args.
func (DeleteBuilder) UseKeys ¶
func (b DeleteBuilder) UseKeys(keys string) DeleteBuilder
UseKeys sets the USE KEYS clause of the query.
func (DeleteBuilder) Where ¶
func (b DeleteBuilder) Where(pred any, args ...any) DeleteBuilder
Where adds an expression to the WHERE clause of the query.
type FTSSearchOptions ¶
type FTSSearchOptions struct { IndexName string Analyzer string Fuzziness int Boost float64 Limit int Score string // Name of the field to store the score in Highlight bool // Whether to enable highlighting Fields []string // Fields to search in }
FTSSearchOptions represents options for a Full-Text Search query
type GenericList ¶
type GenericList[T any] interface { // IsNil returns true if the list is empty IsNil() bool // Cons returns a new list with val as the head Cons(val T) GenericList[T] // Head returns the first element of the list; // panics if the list is empty Head() T // Tail returns a list with all elements except the head; // panics if the list is empty Tail() GenericList[T] // Size returns the list's length. This takes O(1) time. Size() int // ForEach executes a callback for each value in the list. ForEach(f func(T)) // Reverse returns a list whose elements are in the opposite order as // the original list. Reverse() GenericList[T] }
GenericList is a type-safe persistent list using generics.
func NewGenericList ¶
func NewGenericList[T any]() GenericList[T]
NewGenericList returns a new, empty generic list with type parameter T.
type GenericMap ¶
type GenericMap[V any] interface { // IsNil returns true if the Map is empty IsNil() bool // Set returns a new map in which key and value are associated. // If the key didn't exist before, it's created; otherwise, the // associated value is changed. // This operation is O(log N) in the number of keys. Set(key string, value V) GenericMap[V] // Delete returns a new map with the association for key, if any, removed. // This operation is O(log N) in the number of keys. Delete(key string) GenericMap[V] // Lookup returns the value associated with a key, if any. If the key // exists, the second return value is true; otherwise, false. // This operation is O(log N) in the number of keys. Lookup(key string) (V, bool) // Size returns the number of key value pairs in the map. // This takes O(1) time. Size() int // ForEach executes a callback on each key value pair in the map. ForEach(f func(key string, val V)) // Keys returns a slice with all keys in this map. // This operation is O(N) in the number of keys. Keys() []string String() string }
GenericMap is a generic version of Map that uses type parameters to provide type safety for the values.
type InsertBuilder ¶
type InsertBuilder Builder
InsertBuilder builds SQL INSERT statements.
func Insert ¶
func Insert(into string) InsertBuilder
Insert returns a new InsertBuilder with the given table name.
See InsertBuilder.Into.
func (InsertBuilder) Columns ¶
func (b InsertBuilder) Columns(columns ...string) InsertBuilder
Columns adds column names to the query.
func (InsertBuilder) Execute ¶
func (b InsertBuilder) Execute() (QueryResult, error)
Execute builds and executes the query.
func (InsertBuilder) ExecuteContext ¶
func (b InsertBuilder) ExecuteContext(ctx context.Context) (QueryResult, error)
ExecuteContext builds and executes the query with the context and runner set by RunWith.
func (InsertBuilder) Into ¶
func (b InsertBuilder) Into(into string) InsertBuilder
Into sets the INTO clause of the query.
func (InsertBuilder) MustN1ql ¶
func (b InsertBuilder) MustN1ql() (string, []any)
MustN1ql builds the query into a N1QL string and bound args.
MustN1ql panics if there are any errors.
func (InsertBuilder) Options ¶
func (b InsertBuilder) Options(options ...string) InsertBuilder
Options adds options to the query.
func (InsertBuilder) PlaceholderFormat ¶
func (b InsertBuilder) PlaceholderFormat(f PlaceholderFormat) InsertBuilder
PlaceholderFormat sets PlaceholderFormat (e.g. Question or Dollar) for the query.
func (InsertBuilder) Prefix ¶
func (b InsertBuilder) Prefix(sql string, args ...any) InsertBuilder
Prefix adds an expression to the beginning of the query
func (InsertBuilder) PrefixExpr ¶
func (b InsertBuilder) PrefixExpr(expr N1qlizer) InsertBuilder
PrefixExpr adds an expression to the beginning of the query
func (InsertBuilder) RunWith ¶
func (b InsertBuilder) RunWith(runner QueryRunner) InsertBuilder
RunWith sets a Runner (like a Couchbase DB connection) to be used with e.g. Execute.
func (InsertBuilder) RunWithContext ¶
func (b InsertBuilder) RunWithContext(runner QueryRunnerContext) InsertBuilder
RunWithContext sets a Runner (like a Couchbase DB connection with Context support) to be used with e.g. ExecuteContext.
func (InsertBuilder) SetMap ¶
func (b InsertBuilder) SetMap(clauses map[string]any) InsertBuilder
SetMap adds key-value pairs to set rather than a list of values.
func (InsertBuilder) Suffix ¶
func (b InsertBuilder) Suffix(sql string, args ...any) InsertBuilder
Suffix adds an expression to the end of the query
func (InsertBuilder) SuffixExpr ¶
func (b InsertBuilder) SuffixExpr(expr N1qlizer) InsertBuilder
SuffixExpr adds an expression to the end of the query
func (InsertBuilder) ToN1ql ¶
func (b InsertBuilder) ToN1ql() (string, []any, error)
ToN1ql builds the query into a N1QL string and bound args.
func (InsertBuilder) Values ¶
func (b InsertBuilder) Values(values ...any) InsertBuilder
Values adds a single row's values to the query.
type JSONDocument ¶
type JSONDocument struct {
// contains filtered or unexported fields
}
JSONDocument wraps a Go struct or map to be marshaled as a JSON document for Couchbase
func AsDocument ¶
func AsDocument(value any) JSONDocument
AsDocument wraps a value as a JSONDocument
func (JSONDocument) MarshalJSON ¶
func (d JSONDocument) MarshalJSON() ([]byte, error)
MarshalJSON implementation
type LeftNestClause ¶
type LeftNestClause struct {
// contains filtered or unexported fields
}
LeftNestClause represents a LEFT NEST clause in a N1QL query
func LeftNest ¶
func LeftNest(bucket string) LeftNestClause
LeftNest creates a new LEFT NEST clause for outer joining with nested sub-documents
func (LeftNestClause) As ¶
func (ln LeftNestClause) As(alias string) LeftNestClause
As sets the alias for the nested bucket
func (LeftNestClause) On ¶
func (ln LeftNestClause) On(condition interface{}, args ...interface{}) LeftNestClause
On sets the ON condition for the LEFT NEST clause
func (LeftNestClause) OnKeys ¶
func (ln LeftNestClause) OnKeys(keys string) LeftNestClause
OnKeys sets the ON KEYS expression for the LEFT NEST clause
func (LeftNestClause) ToN1ql ¶
func (ln LeftNestClause) ToN1ql() (string, []interface{}, error)
ToN1ql implements the N1qlizer interface
type LeftUnnestClause ¶
type LeftUnnestClause struct {
// contains filtered or unexported fields
}
LeftUnnestClause represents a LEFT UNNEST clause in a N1QL query
func LeftUnnest ¶
func LeftUnnest(path string) LeftUnnestClause
LeftUnnest creates a new LEFT UNNEST clause for outer flattening of array fields
func (LeftUnnestClause) As ¶
func (lu LeftUnnestClause) As(alias string) LeftUnnestClause
As sets the alias for the unnested array
func (LeftUnnestClause) On ¶
func (lu LeftUnnestClause) On(condition interface{}, args ...interface{}) LeftUnnestClause
On sets the ON condition for the LEFT UNNEST clause
func (LeftUnnestClause) ToN1ql ¶
func (lu LeftUnnestClause) ToN1ql() (string, []interface{}, error)
ToN1ql implements the N1qlizer interface
type List ¶
type List interface { // IsNil returns true if the list is empty IsNil() bool // Cons returns a new list with val as the head Cons(val any) List // Head returns the first element of the list; // panics if the list is empty Head() any // Tail returns a list with all elements except the head; // panics if the list is empty Tail() List // Size returns the list's length. This takes O(1) time. Size() int // ForEach executes a callback for each value in the list. ForEach(f func(any)) // Reverse returns a list whose elements are in the opposite order as // the original list. Reverse() List }
List is a persistent list of possibly heterogeneous values.
type Map ¶
type Map interface { // IsNil returns true if the Map is empty IsNil() bool // Set returns a new map in which key and value are associated. // If the key didn't exist before, it's created; otherwise, the // associated value is changed. // This operation is O(log N) in the number of keys. Set(key string, value any) Map // Delete returns a new map with the association for key, if any, removed. // This operation is O(log N) in the number of keys. Delete(key string) Map // Lookup returns the value associated with a key, if any. If the key // exists, the second return value is true; otherwise, false. // This operation is O(log N) in the number of keys. Lookup(key string) (any, bool) // Size returns the number of key value pairs in the map. // This takes O(1) time. Size() int // ForEach executes a callback on each key value pair in the map. ForEach(f func(key string, val any)) // Keys returns a slice with all keys in this map. // This operation is O(N) in the number of keys. Keys() []string String() string }
A Map associates unique keys (type string) with values (type any).
type N1qlizer ¶
N1qlizer is the interface that wraps the ToN1ql method.
ToN1ql returns a N1QL representation of the N1qlizer, along with a slice of args as passed to Couchbase SDK. It can also return an error.
func ArrayCount ¶
ArrayCount returns an Analytics array_count function call
func ArrayFilter ¶
ArrayFilter returns an Analytics array_filter function call
func ArrayFlatten ¶
ArrayFlatten returns an Analytics array_flatten function call
func Expr ¶
Expr builds an expression from a SQL fragment and arguments. The first argument should be a string, which may contain ? placeholders.
func FTSConjunction ¶
FTSConjunction creates a conjunction (AND) of multiple FTS expressions
func FTSDisjunction ¶
FTSDisjunction creates a disjunction (OR) of multiple FTS expressions
func FTSMatch ¶
func FTSMatch(query string, options ...FTSSearchOptions) N1qlizer
FTSMatch creates a Full-Text Search match expression
func FTSPhraseMatch ¶
func FTSPhraseMatch(query string, options ...FTSSearchOptions) N1qlizer
FTSPhraseMatch creates a Full-Text Search phrase match expression
func FTSPrefixMatch ¶
func FTSPrefixMatch(prefix string, options ...FTSSearchOptions) N1qlizer
FTSPrefixMatch creates a Full-Text Search prefix match expression
func FTSRangeMatch ¶
func FTSRangeMatch(field string, min, max interface{}, options ...FTSSearchOptions) N1qlizer
FTSRangeMatch creates a Full-Text Search range match expression
func FTSSearchService ¶
FTSSearchService creates an expression to use Couchbase's dedicated search service
func FTSWildcardMatch ¶
func FTSWildcardMatch(pattern string, options ...FTSSearchOptions) N1qlizer
FTSWildcardMatch creates a Full-Text Search wildcard match expression
func JSONArrayContains ¶
JSONArrayContains creates an expression for checking if a JSON array contains a value field ARRAY_CONTAINS value
func JSONObject ¶
JSONObject creates an object constructor expression for N1QL
func ObjectNames ¶
ObjectNames returns an Analytics object_names function call
func ObjectPairs ¶
ObjectPairs returns an Analytics object_pairs function call
func ObjectRemove ¶
ObjectRemove returns an Analytics object_remove function call
func ObjectValues ¶
ObjectValues returns an Analytics object_values function call
func SubDocument ¶
SubDocument returns a subdocument expression
type NestClause ¶
type NestClause struct {
// contains filtered or unexported fields
}
NestClause represents a NEST clause in a N1QL query
func Nest ¶
func Nest(bucket string) NestClause
Nest creates a new NEST clause for joining with nested sub-documents
func (NestClause) As ¶
func (n NestClause) As(alias string) NestClause
As sets the alias for the nested bucket
func (NestClause) On ¶
func (n NestClause) On(condition interface{}, args ...interface{}) NestClause
On sets the ON condition for the NEST clause
func (NestClause) OnKeys ¶
func (n NestClause) OnKeys(keys string) NestClause
OnKeys sets the ON KEYS expression for the NEST clause
func (NestClause) ToN1ql ¶
func (n NestClause) ToN1ql() (string, []interface{}, error)
ToN1ql implements the N1qlizer interface
type NestedField ¶
NestedField is a helper for accessing nested JSON fields
func (NestedField) String ¶
func (n NestedField) String() string
String returns the full path as a string
type PlaceholderFormat ¶
PlaceholderFormat is the interface that wraps the ReplacePlaceholders method.
type QueryExecutor ¶
type QueryExecutor interface {
Execute(query string, args ...any) (QueryResult, error)
}
QueryExecutor is the interface that wraps the Execute method.
Execute executes the given N1QL query as implemented by Couchbase SDK.
type QueryExecutorContext ¶
type QueryExecutorContext interface {
ExecuteContext(ctx context.Context, query string, args ...any) (QueryResult, error)
}
QueryExecutorContext is the interface that wraps the ExecuteContext method.
ExecuteContext executes the given N1QL query with context as implemented by Couchbase SDK.
type QueryResult ¶
QueryResult represents the result of a N1QL query
func ExecuteContextWith ¶
func ExecuteContextWith(ctx context.Context, db QueryExecutorContext, n N1qlizer) (res QueryResult, err error)
ExecuteContextWith executes the given N1QLizer with context using the provided QueryExecutorContext.
func ExecuteWith ¶
func ExecuteWith(db QueryExecutor, n N1qlizer) (res QueryResult, err error)
ExecuteWith executes the given N1QLizer using the provided QueryExecutor. This function is similar to ExecuteContextWith but does not use a context.
type QueryRunner ¶
type QueryRunner interface { QueryExecutor }
QueryRunner is the interface that combines query execution and result handling
func WrapStdCb ¶
func WrapStdCb(stdCb StdCb) QueryRunner
WrapStdCb wraps a type implementing the standard Couchbase SDK interface with methods that n1qlizer expects.
type QueryRunnerContext ¶
type QueryRunnerContext interface { QueryExecutor QueryExecutorContext }
QueryRunnerContext is the interface that combines QueryExecutor and QueryExecutorContext.
func WrapStdCbCtx ¶
func WrapStdCbCtx(stdCb StdCbCtx) QueryRunnerContext
WrapStdCbCtx wraps a type implementing the standard Couchbase SDK interface with context support with methods that n1qlizer expects.
type SelectBuilder ¶
type SelectBuilder Builder
SelectBuilder builds SELECT statements.
func Select ¶
func Select(columns ...string) SelectBuilder
Select returns a new SelectBuilder, optionally setting some result columns.
See SelectBuilder.Columns.
func (SelectBuilder) Column ¶
func (b SelectBuilder) Column(column any, args ...any) SelectBuilder
Column adds a result column to the query. Unlike Columns, Column accepts args which will be bound to placeholders in the column string, for example:
.Column("IF(n_subscribers > ?, ?, ?)", 100, "HIGH", "LOW")
func (SelectBuilder) Columns ¶
func (b SelectBuilder) Columns(columns ...string) SelectBuilder
Columns adds result columns to the query.
func (SelectBuilder) Distinct ¶
func (b SelectBuilder) Distinct() SelectBuilder
Distinct adds a DISTINCT clause to the query.
func (SelectBuilder) Execute ¶
func (b SelectBuilder) Execute() (QueryResult, error)
Execute builds and executes the query.
func (SelectBuilder) ExecuteContext ¶
func (b SelectBuilder) ExecuteContext(ctx context.Context) (QueryResult, error)
ExecuteContext builds and executes the query with the context and runner set by RunWith.
func (SelectBuilder) From ¶
func (b SelectBuilder) From(from string) SelectBuilder
From sets the FROM clause of the query.
func (SelectBuilder) FromSelect ¶
func (b SelectBuilder) FromSelect(from SelectBuilder, alias string) SelectBuilder
FromSelect sets a subquery into the FROM clause of the query.
func (SelectBuilder) GroupBy ¶
func (b SelectBuilder) GroupBy(groupBys ...string) SelectBuilder
GroupBy adds GROUP BY expressions to the query.
func (SelectBuilder) Having ¶
func (b SelectBuilder) Having(pred any, rest ...any) SelectBuilder
Having adds an expression to the HAVING clause of the query.
func (SelectBuilder) InnerJoin ¶
func (b SelectBuilder) InnerJoin(join string, rest ...any) SelectBuilder
InnerJoin adds an INNER JOIN clause to the query.
func (SelectBuilder) Join ¶
func (b SelectBuilder) Join(join string, rest ...any) SelectBuilder
Join adds a JOIN clause to the query.
func (SelectBuilder) JoinClause ¶
func (b SelectBuilder) JoinClause(join string, args ...any) SelectBuilder
JoinClause adds a join clause to the query.
func (SelectBuilder) LeftJoin ¶
func (b SelectBuilder) LeftJoin(join string, rest ...any) SelectBuilder
LeftJoin adds a LEFT JOIN clause to the query.
func (SelectBuilder) LeftNest ¶
func (b SelectBuilder) LeftNest(bucket string) SelectBuilder
LeftNest adds a LEFT NEST clause to the query
func (SelectBuilder) LeftNestClause ¶
func (b SelectBuilder) LeftNestClause(nest LeftNestClause) SelectBuilder
LeftNestClause adds a LEFT NEST clause to the query
func (SelectBuilder) LeftUnnest ¶
func (b SelectBuilder) LeftUnnest(path string) SelectBuilder
LeftUnnest adds a LEFT UNNEST clause to the query
func (SelectBuilder) LeftUnnestClause ¶
func (b SelectBuilder) LeftUnnestClause(unnest LeftUnnestClause) SelectBuilder
LeftUnnestClause adds a LEFT UNNEST clause to the query
func (SelectBuilder) Limit ¶
func (b SelectBuilder) Limit(limit uint64) SelectBuilder
Limit sets a LIMIT clause on the query.
func (SelectBuilder) MustN1ql ¶
func (b SelectBuilder) MustN1ql() (string, []any)
MustN1ql builds the query into a N1QL string and bound args.
MustN1ql panics if there are any errors.
func (SelectBuilder) Nest ¶
func (b SelectBuilder) Nest(bucket string) SelectBuilder
Nest adds a NEST clause to the query
func (SelectBuilder) NestClause ¶
func (b SelectBuilder) NestClause(nest NestClause) SelectBuilder
NestClause adds a NEST clause to the query
func (SelectBuilder) Offset ¶
func (b SelectBuilder) Offset(offset uint64) SelectBuilder
Offset sets an OFFSET clause on the query.
func (SelectBuilder) Options ¶
func (b SelectBuilder) Options(options ...string) SelectBuilder
Options adds options to the query.
func (SelectBuilder) OrderBy ¶
func (b SelectBuilder) OrderBy(orderBys ...string) SelectBuilder
OrderBy adds ORDER BY expressions to the query.
func (SelectBuilder) OrderByClause ¶
func (b SelectBuilder) OrderByClause(pred any, args ...any) SelectBuilder
OrderByClause adds ORDER BY expressions to the query with a custom clause.
This is a more flexible version of OrderBy, and can be used for complex expressions like "ORDER BY field ASC NULLS FIRST".
func (SelectBuilder) PlaceholderFormat ¶
func (b SelectBuilder) PlaceholderFormat(f PlaceholderFormat) SelectBuilder
PlaceholderFormat sets PlaceholderFormat (e.g. Question or Dollar) for the query.
func (SelectBuilder) Prefix ¶
func (b SelectBuilder) Prefix(sql string, args ...any) SelectBuilder
Prefix adds an expression to the beginning of the query
func (SelectBuilder) PrefixExpr ¶
func (b SelectBuilder) PrefixExpr(expr N1qlizer) SelectBuilder
PrefixExpr adds an expression to the very beginning of the query
func (SelectBuilder) RightJoin ¶
func (b SelectBuilder) RightJoin(join string, rest ...any) SelectBuilder
RightJoin adds a RIGHT JOIN clause to the query.
func (SelectBuilder) RunWith ¶
func (b SelectBuilder) RunWith(runner QueryRunner) SelectBuilder
RunWith sets a Runner (like a Couchbase DB connection) to be used with e.g. Execute.
func (SelectBuilder) RunWithContext ¶
func (b SelectBuilder) RunWithContext(runner QueryRunnerContext) SelectBuilder
RunWithContext sets a Runner (like a Couchbase DB connection with Context support) to be used with e.g. ExecuteContext.
func (SelectBuilder) Suffix ¶
func (b SelectBuilder) Suffix(sql string, args ...any) SelectBuilder
Suffix adds an expression to the end of the query
func (SelectBuilder) SuffixExpr ¶
func (b SelectBuilder) SuffixExpr(expr N1qlizer) SelectBuilder
SuffixExpr adds an expression to the end of the query
func (SelectBuilder) ToN1ql ¶
func (b SelectBuilder) ToN1ql() (string, []any, error)
ToN1ql builds the query into a N1QL string and bound args.
func (SelectBuilder) Unnest ¶
func (b SelectBuilder) Unnest(path string) SelectBuilder
Unnest adds an UNNEST clause to the query
func (SelectBuilder) UnnestClause ¶
func (b SelectBuilder) UnnestClause(unnest UnnestClause) SelectBuilder
UnnestClause adds an UNNEST clause to the query
func (SelectBuilder) UseKeys ¶
func (b SelectBuilder) UseKeys(keys string) SelectBuilder
UseKeys sets the USE KEYS clause of the query.
func (SelectBuilder) Where ¶
func (b SelectBuilder) Where(pred any, args ...any) SelectBuilder
Where adds an expression to the WHERE clause of the query.
func (SelectBuilder) WithSearch ¶
func (b SelectBuilder) WithSearch(search N1qlizer) SelectBuilder
WithSearch adds a SEARCH clause to the WHERE part of a query
type StatementBuilderType ¶
type StatementBuilderType Builder
StatementBuilderType is the type of StatementBuilder.
func (StatementBuilderType) AnalyticsSelect ¶
func (b StatementBuilderType) AnalyticsSelect(columns ...string) AnalyticsSelectBuilder
AnalyticsSelect returns an AnalyticsSelectBuilder for this StatementBuilderType. This is specific to the Couchbase Analytics Service.
func (StatementBuilderType) Delete ¶
func (b StatementBuilderType) Delete(from string) DeleteBuilder
Delete returns a DeleteBuilder for this StatementBuilderType.
func (StatementBuilderType) Insert ¶
func (b StatementBuilderType) Insert(into string) InsertBuilder
Insert returns a InsertBuilder for this StatementBuilderType.
func (StatementBuilderType) PlaceholderFormat ¶
func (b StatementBuilderType) PlaceholderFormat(f PlaceholderFormat) StatementBuilderType
PlaceholderFormat sets the PlaceholderFormat for this StatementBuilderType.
func (StatementBuilderType) RunWith ¶
func (b StatementBuilderType) RunWith(runner QueryRunner) StatementBuilderType
RunWith sets the QueryRunner that this StatementBuilderType should execute queries with.
func (StatementBuilderType) RunWithContext ¶
func (b StatementBuilderType) RunWithContext(runner QueryRunnerContext) StatementBuilderType
RunWithContext sets the QueryRunnerContext that this StatementBuilderType should execute queries with context support.
func (StatementBuilderType) Select ¶
func (b StatementBuilderType) Select(columns ...string) SelectBuilder
Select returns a SelectBuilder for this StatementBuilderType.
func (StatementBuilderType) Update ¶
func (b StatementBuilderType) Update(table string) UpdateBuilder
Update returns a UpdateBuilder for this StatementBuilderType.
func (StatementBuilderType) Upsert ¶
func (b StatementBuilderType) Upsert(into string) UpsertBuilder
Upsert returns a UpsertBuilder for this StatementBuilderType. This is specific to Couchbase and is the preferred way to insert documents.
type StdCb ¶
type StdCb interface {
Execute(query string, args ...any) (QueryResult, error)
}
StdCb encompasses the standard methods of Couchbase SDK that execute queries.
type StdCbCtx ¶
type StdCbCtx interface {
ExecuteContext(ctx context.Context, query string, args ...any) (QueryResult, error)
}
StdCbCtx encompasses the standard methods of Couchbase SDK that execute queries with context.
type UnnestClause ¶
type UnnestClause struct {
// contains filtered or unexported fields
}
UnnestClause represents an UNNEST clause in a N1QL query
func Unnest ¶
func Unnest(path string) UnnestClause
Unnest creates a new UNNEST clause for flattening array fields
func (UnnestClause) As ¶
func (u UnnestClause) As(alias string) UnnestClause
As sets the alias for the unnested array
func (UnnestClause) On ¶
func (u UnnestClause) On(condition interface{}, args ...interface{}) UnnestClause
On sets the ON condition for the UNNEST clause
func (UnnestClause) ToN1ql ¶
func (u UnnestClause) ToN1ql() (string, []interface{}, error)
ToN1ql implements the N1qlizer interface
type UpdateBuilder ¶
type UpdateBuilder Builder
UpdateBuilder builds UPDATE statements.
func Update ¶
func Update(table string) UpdateBuilder
Update returns a new UpdateBuilder with the given table name.
See UpdateBuilder.Table.
func (UpdateBuilder) Execute ¶
func (b UpdateBuilder) Execute() (QueryResult, error)
Execute builds and executes the query.
func (UpdateBuilder) ExecuteContext ¶
func (b UpdateBuilder) ExecuteContext(ctx context.Context) (QueryResult, error)
ExecuteContext builds and executes the query with the context and runner set by RunWith.
func (UpdateBuilder) Limit ¶
func (b UpdateBuilder) Limit(limit uint64) UpdateBuilder
Limit sets a LIMIT clause on the query.
func (UpdateBuilder) MustN1ql ¶
func (b UpdateBuilder) MustN1ql() (string, []any)
MustN1ql builds the query into a N1QL string and bound args.
MustN1ql panics if there are any errors.
func (UpdateBuilder) Offset ¶
func (b UpdateBuilder) Offset(offset uint64) UpdateBuilder
Offset sets a OFFSET clause on the query.
func (UpdateBuilder) PlaceholderFormat ¶
func (b UpdateBuilder) PlaceholderFormat(f PlaceholderFormat) UpdateBuilder
PlaceholderFormat sets PlaceholderFormat (e.g. Question or Dollar) for the query.
func (UpdateBuilder) Prefix ¶
func (b UpdateBuilder) Prefix(sql string, args ...any) UpdateBuilder
Prefix adds an expression to the beginning of the query
func (UpdateBuilder) PrefixExpr ¶
func (b UpdateBuilder) PrefixExpr(expr N1qlizer) UpdateBuilder
PrefixExpr adds an expression to the beginning of the query
func (UpdateBuilder) RunWith ¶
func (b UpdateBuilder) RunWith(runner QueryRunner) UpdateBuilder
RunWith sets a Runner (like a Couchbase DB connection) to be used with e.g. Execute.
func (UpdateBuilder) RunWithContext ¶
func (b UpdateBuilder) RunWithContext(runner QueryRunnerContext) UpdateBuilder
RunWithContext sets a Runner (like a Couchbase DB connection with Context support) to be used with e.g. ExecuteContext.
func (UpdateBuilder) Set ¶
func (b UpdateBuilder) Set(column string, value any) UpdateBuilder
Set adds SET clauses to the query.
func (UpdateBuilder) SetMap ¶
func (b UpdateBuilder) SetMap(clauses map[string]any) UpdateBuilder
SetMap is a convenience method which calls .Set for each key/value pair in clauses.
func (UpdateBuilder) Suffix ¶
func (b UpdateBuilder) Suffix(sql string, args ...any) UpdateBuilder
Suffix adds an expression to the end of the query
func (UpdateBuilder) SuffixExpr ¶
func (b UpdateBuilder) SuffixExpr(expr N1qlizer) UpdateBuilder
SuffixExpr adds an expression to the end of the query
func (UpdateBuilder) Table ¶
func (b UpdateBuilder) Table(table string) UpdateBuilder
Table sets the table to be updated.
func (UpdateBuilder) ToN1ql ¶
func (b UpdateBuilder) ToN1ql() (string, []any, error)
ToN1ql builds the query into a N1QL string and bound args.
func (UpdateBuilder) UseKeys ¶
func (b UpdateBuilder) UseKeys(keys string) UpdateBuilder
UseKeys sets the USE KEYS clause of the query.
func (UpdateBuilder) Where ¶
func (b UpdateBuilder) Where(pred any, args ...any) UpdateBuilder
Where adds WHERE expressions to the query.
type UpsertBuilder ¶
type UpsertBuilder Builder
UpsertBuilder builds Couchbase N1QL UPSERT statements.
func Upsert ¶
func Upsert(into string) UpsertBuilder
Upsert returns a new UpsertBuilder with the given table name.
See UpsertBuilder.Into.
func (UpsertBuilder) Columns ¶
func (b UpsertBuilder) Columns(columns ...string) UpsertBuilder
Columns adds column names to the query.
func (UpsertBuilder) Document ¶
func (b UpsertBuilder) Document(key string, value any) UpsertBuilder
Document sets the document key and value for the UPSERT operation. Specific to Couchbase, uses (KEY, VALUE) syntax.
func (UpsertBuilder) Execute ¶
func (b UpsertBuilder) Execute() (QueryResult, error)
Execute builds and executes the query.
func (UpsertBuilder) ExecuteContext ¶
func (b UpsertBuilder) ExecuteContext(ctx context.Context) (QueryResult, error)
ExecuteContext builds and executes the query with the context and runner set by RunWith.
func (UpsertBuilder) Into ¶
func (b UpsertBuilder) Into(into string) UpsertBuilder
Into sets the INTO clause of the query.
func (UpsertBuilder) MustN1ql ¶
func (b UpsertBuilder) MustN1ql() (string, []any)
MustN1ql builds the query into a N1QL string and bound args.
MustN1ql panics if there are any errors.
func (UpsertBuilder) Options ¶
func (b UpsertBuilder) Options(options ...string) UpsertBuilder
Options adds options to the query.
func (UpsertBuilder) PlaceholderFormat ¶
func (b UpsertBuilder) PlaceholderFormat(f PlaceholderFormat) UpsertBuilder
PlaceholderFormat sets PlaceholderFormat (e.g. Question or Dollar) for the query.
func (UpsertBuilder) Prefix ¶
func (b UpsertBuilder) Prefix(sql string, args ...any) UpsertBuilder
Prefix adds an expression to the beginning of the query
func (UpsertBuilder) PrefixExpr ¶
func (b UpsertBuilder) PrefixExpr(expr N1qlizer) UpsertBuilder
PrefixExpr adds an expression to the beginning of the query
func (UpsertBuilder) RunWith ¶
func (b UpsertBuilder) RunWith(runner QueryRunner) UpsertBuilder
RunWith sets a Runner (like a Couchbase DB connection) to be used with e.g. Execute.
func (UpsertBuilder) RunWithContext ¶
func (b UpsertBuilder) RunWithContext(runner QueryRunnerContext) UpsertBuilder
RunWithContext sets a Runner (like a Couchbase DB connection with Context support) to be used with e.g. ExecuteContext.
func (UpsertBuilder) SetMap ¶
func (b UpsertBuilder) SetMap(clauses map[string]any) UpsertBuilder
SetMap adds key-value pairs to set rather than a list of values.
func (UpsertBuilder) Suffix ¶
func (b UpsertBuilder) Suffix(sql string, args ...any) UpsertBuilder
Suffix adds an expression to the end of the query
func (UpsertBuilder) SuffixExpr ¶
func (b UpsertBuilder) SuffixExpr(expr N1qlizer) UpsertBuilder
SuffixExpr adds an expression to the end of the query
func (UpsertBuilder) ToN1ql ¶
func (b UpsertBuilder) ToN1ql() (string, []any, error)
ToN1ql builds the query into a N1QL string and bound args.
func (UpsertBuilder) Values ¶
func (b UpsertBuilder) Values(values ...any) UpsertBuilder
Values adds a single row's values to the query.
type UseIndex ¶
UseIndex adds support for Couchbase's USE INDEX clause
func UseIndexGSI ¶
UseIndexGSI creates a USE INDEX clause for a GSI index
func UseIndexView ¶
UseIndexView creates a USE INDEX clause for a VIEW index