mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 07:07:32 +00:00
move files
This commit is contained in:
66
backend/v3/storage/database/query.go
Normal file
66
backend/v3/storage/database/query.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package database
|
||||
|
||||
type QueryOption func(opts *QueryOpts)
|
||||
|
||||
func WithCondition(condition Condition) QueryOption {
|
||||
return func(opts *QueryOpts) {
|
||||
opts.Condition = condition
|
||||
}
|
||||
}
|
||||
|
||||
func WithOrderBy(orderBy ...Column) QueryOption {
|
||||
return func(opts *QueryOpts) {
|
||||
opts.OrderBy = orderBy
|
||||
}
|
||||
}
|
||||
|
||||
func WithLimit(limit uint32) QueryOption {
|
||||
return func(opts *QueryOpts) {
|
||||
opts.Limit = limit
|
||||
}
|
||||
}
|
||||
|
||||
func WithOffset(offset uint32) QueryOption {
|
||||
return func(opts *QueryOpts) {
|
||||
opts.Offset = offset
|
||||
}
|
||||
}
|
||||
|
||||
type QueryOpts struct {
|
||||
Condition Condition
|
||||
OrderBy Columns
|
||||
Limit uint32
|
||||
Offset uint32
|
||||
}
|
||||
|
||||
func (opts *QueryOpts) WriteCondition(builder *StatementBuilder) {
|
||||
if opts.Condition == nil {
|
||||
return
|
||||
}
|
||||
builder.WriteString(" WHERE ")
|
||||
opts.Condition.Write(builder)
|
||||
}
|
||||
|
||||
func (opts *QueryOpts) WriteOrderBy(builder *StatementBuilder) {
|
||||
if len(opts.OrderBy) == 0 {
|
||||
return
|
||||
}
|
||||
builder.WriteString(" ORDER BY ")
|
||||
Columns(opts.OrderBy).Write(builder)
|
||||
}
|
||||
|
||||
func (opts *QueryOpts) WriteLimit(builder *StatementBuilder) {
|
||||
if opts.Limit == 0 {
|
||||
return
|
||||
}
|
||||
builder.WriteString(" LIMIT ")
|
||||
builder.WriteArg(opts.Limit)
|
||||
}
|
||||
|
||||
func (opts *QueryOpts) WriteOffset(builder *StatementBuilder) {
|
||||
if opts.Offset == 0 {
|
||||
return
|
||||
}
|
||||
builder.WriteString(" OFFSET ")
|
||||
builder.WriteArg(opts.Offset)
|
||||
}
|
Reference in New Issue
Block a user