database

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolPtr added in v0.7.1

func BoolPtr(v bool) *bool

func Float64Ptr added in v0.7.1

func Float64Ptr(v float64) *float64

func GetTypeName added in v0.7.1

func GetTypeName(v any) string

Helper to get the underlying type name for reflection-based operations

func Int32Ptr added in v0.7.1

func Int32Ptr(v int32) *int32

func Int64Ptr added in v0.7.1

func Int64Ptr(v int64) *int64

Helper functions for common operations

func StringPtr added in v0.7.1

func StringPtr(v string) *string

Types

type AggregateOptions added in v0.7.1

type AggregateOptions struct {
	AllowDiskUse             *bool
	BatchSize                *int32
	BypassDocumentValidation *bool
	MaxTime                  *time.Duration
	UseCursor                *bool
}

type BulkWriteOptions added in v0.7.1

type BulkWriteOptions struct {
	BypassDocumentValidation *bool
	Ordered                  *bool
}

type ChangeStream added in v0.7.1

type ChangeStream interface {
	Next(ctx context.Context) bool
	TryNext(ctx context.Context) bool
	Decode(val any) error
	Err() error
	Close(ctx context.Context) error
	ResumeToken() bson.Raw
}

ChangeStream represents a change stream for watching collection changes

type ChangeStreamOptions added in v0.7.1

type ChangeStreamOptions struct {
	BatchSize            *int32
	FullDocument         *string
	MaxAwaitTime         *time.Duration
	ResumeAfter          any
	StartAtOperationTime any
	StartAfter           any
}

type ChangeStreamPreAndPostImages added in v0.7.1

type ChangeStreamPreAndPostImages struct {
	Enabled *bool
}

type Collation added in v0.7.1

type Collation struct {
	Locale          *string
	CaseLevel       *bool
	CaseFirst       *string
	Strength        *int32
	NumericOrdering *bool
	Alternate       *string
	MaxVariable     *string
	Backwards       *bool
}

type CountOptions added in v0.7.1

type CountOptions struct {
	Skip    *int64
	Limit   *int64
	MaxTime *time.Duration
}

type CreateCollectionOptions added in v0.7.1

type CreateCollectionOptions struct {
	Capped                       *bool
	SizeInBytes                  *int64
	MaxDocuments                 *int64
	StorageEngine                any
	Validator                    any
	ValidationLevel              *string
	ValidationAction             *string
	IndexOptionDefaults          any
	ViewOn                       *string
	Pipeline                     any
	Collation                    *Collation
	ChangeStreamPreAndPostImages *ChangeStreamPreAndPostImages
}

type DeleteOptions added in v0.7.1

type DeleteOptions struct {
}

type DistinctOptions added in v0.7.1

type DistinctOptions struct {
	MaxTime *time.Duration
}

type DocumentBulkWriteResult added in v0.7.1

type DocumentBulkWriteResult interface {
	InsertedCount() int64
	MatchedCount() int64
	ModifiedCount() int64
	DeletedCount() int64
	UpsertedCount() int64
	UpsertedIDs() map[int64]any
}

DocumentBulkWriteResult represents the result of a bulk write operation

type DocumentCollection added in v0.7.1

type DocumentCollection interface {
	// Single document operations
	InsertOne(ctx context.Context, document any, opts *InsertOneOptions) (any, error)
	FindOne(ctx context.Context, filter any, opts *FindOneOptions) DocumentResult
	UpdateOne(ctx context.Context, filter any, update any, opts *UpdateOptions) (DocumentUpdateResult, error)
	ReplaceOne(ctx context.Context, filter any, replacement any, opts *ReplaceOptions) (DocumentUpdateResult, error)
	DeleteOne(ctx context.Context, filter any, opts *DeleteOptions) (DocumentDeleteResult, error)

	// Multiple document operations
	InsertMany(ctx context.Context, documents []any, opts *InsertManyOptions) ([]any, error)
	Find(ctx context.Context, filter any, opts *FindOptions) (DocumentCursor, error)
	UpdateMany(ctx context.Context, filter any, update any, opts *UpdateOptions) (DocumentUpdateResult, error)
	DeleteMany(ctx context.Context, filter any, opts *DeleteOptions) (DocumentDeleteResult, error)

	// Count operations
	CountDocuments(ctx context.Context, filter any, opts *CountOptions) (int64, error)
	EstimatedDocumentCount(ctx context.Context, opts *EstimatedCountOptions) (int64, error)

	// Aggregation operations
	Aggregate(ctx context.Context, pipeline any, opts *AggregateOptions) (DocumentCursor, error)
	Distinct(ctx context.Context, fieldName string, filter any, opts *DistinctOptions) ([]any, error)

	// Index operations
	CreateIndex(ctx context.Context, model IndexModel) error
	CreateIndexes(ctx context.Context, models []IndexModel) error
	DropIndex(ctx context.Context, name string) error
	ListIndexes(ctx context.Context) (DocumentCursor, error)

	// Bulk operations
	BulkWrite(ctx context.Context, models []WriteModel, opts *BulkWriteOptions) (DocumentBulkWriteResult, error)

	// Watch changes (if supported)
	Watch(ctx context.Context, pipeline any, opts *ChangeStreamOptions) (ChangeStream, error)
}

DocumentCollection defines operations on a specific collection

type DocumentCursor added in v0.7.1

type DocumentCursor interface {
	// Iteration
	Next(ctx context.Context) bool
	TryNext(ctx context.Context) bool
	Decode(val any) error
	All(ctx context.Context, results any) error

	// Cursor management
	Close(ctx context.Context) error
	Err() error
	ID() int64

	// Current document access
	Current() bson.Raw
}

DocumentCursor represents a cursor for iterating over query results

type DocumentDeleteResult added in v0.7.1

type DocumentDeleteResult interface {
	DeletedCount() int64
}

DocumentDeleteResult represents the result of a delete operation

type DocumentInterface added in v0.7.1

type DocumentInterface interface {
	// Collection operations
	Collection(name string) DocumentCollection

	// Database-level operations
	CreateCollection(ctx context.Context, name string, opts *CreateCollectionOptions) error
	DropCollection(ctx context.Context, name string) error

	// Index operations
	CreateIndex(ctx context.Context, collection string, model IndexModel) error
	DropIndex(ctx context.Context, collection string, name string) error
	ListIndexes(ctx context.Context, collection string) ([]IndexModel, error)

	// Aggregation operations
	Aggregate(ctx context.Context, collection string, pipeline any, opts *AggregateOptions) (DocumentCursor, error)

	// Database administration
	RunCommand(ctx context.Context, command any) DocumentResult
}

DocumentInterface defines operations for document-oriented databases like MongoDB This interface provides native document database operations alongside the SQL-compatible Interface

func AsDocumentInterface added in v0.7.1

func AsDocumentInterface(db Interface) (DocumentInterface, bool)

Type assertions for checking if an Interface also implements DocumentInterface

type DocumentResult added in v0.7.1

type DocumentResult interface {
	Decode(v any) error
	Err() error
}

DocumentResult represents a single document result

type DocumentUpdateResult added in v0.7.1

type DocumentUpdateResult interface {
	MatchedCount() int64
	ModifiedCount() int64
	UpsertedCount() int64
	UpsertedID() any
}

DocumentUpdateResult represents the result of an update operation

type EstimatedCountOptions added in v0.7.1

type EstimatedCountOptions struct {
	MaxTime *time.Duration
}

type FilterBuilder added in v0.7.1

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

FilterBuilder provides a fluent interface for building MongoDB filters

func Filter added in v0.7.1

func Filter() FilterBuilder

Utility functions for creating common filter types

func (FilterBuilder) And added in v0.7.1

func (fb FilterBuilder) And(filters ...any) FilterBuilder

func (FilterBuilder) Build added in v0.7.1

func (fb FilterBuilder) Build() bson.M

func (FilterBuilder) Eq added in v0.7.1

func (fb FilterBuilder) Eq(field string, value any) FilterBuilder

func (FilterBuilder) Exists added in v0.7.1

func (fb FilterBuilder) Exists(field string, exists bool) FilterBuilder

func (FilterBuilder) Gt added in v0.7.1

func (fb FilterBuilder) Gt(field string, value any) FilterBuilder

func (FilterBuilder) Gte added in v0.7.1

func (fb FilterBuilder) Gte(field string, value any) FilterBuilder

func (FilterBuilder) In added in v0.7.1

func (fb FilterBuilder) In(field string, values ...any) FilterBuilder

func (FilterBuilder) Lt added in v0.7.1

func (fb FilterBuilder) Lt(field string, value any) FilterBuilder

func (FilterBuilder) Lte added in v0.7.1

func (fb FilterBuilder) Lte(field string, value any) FilterBuilder

func (FilterBuilder) Ne added in v0.7.1

func (fb FilterBuilder) Ne(field string, value any) FilterBuilder

func (FilterBuilder) Nin added in v0.7.1

func (fb FilterBuilder) Nin(field string, values ...any) FilterBuilder

func (FilterBuilder) Nor added in v0.7.1

func (fb FilterBuilder) Nor(filters ...any) FilterBuilder

func (FilterBuilder) Not added in v0.7.1

func (fb FilterBuilder) Not(filter any) FilterBuilder

func (FilterBuilder) Or added in v0.7.1

func (fb FilterBuilder) Or(filters ...any) FilterBuilder

func (FilterBuilder) Regex added in v0.7.1

func (fb FilterBuilder) Regex(field, pattern, options string) FilterBuilder

func (FilterBuilder) Type added in v0.7.1

func (fb FilterBuilder) Type(field string, bsonType any) FilterBuilder

type FindOneOptions added in v0.7.1

type FindOneOptions struct {
	Sort                any
	Skip                *int64
	Projection          any
	MaxTime             *time.Duration
	ShowRecordID        *bool
	AllowPartialResults *bool
}

type FindOptions added in v0.7.1

type FindOptions struct {
	Sort                any
	Skip                *int64
	Limit               *int64
	Projection          any
	MaxTime             *time.Duration
	ShowRecordID        *bool
	AllowPartialResults *bool
	BatchSize           *int32
	NoCursorTimeout     *bool
}

type IndexModel added in v0.7.1

type IndexModel struct {
	Keys    any
	Options *IndexOptions
}

IndexModel represents an index specification

type IndexOptions added in v0.7.1

type IndexOptions struct {
	Background              *bool
	ExpireAfterSeconds      *int32
	Name                    *string
	Sparse                  *bool
	StorageEngine           any
	Unique                  *bool
	Version                 *int32
	DefaultLanguage         *string
	LanguageOverride        *string
	TextVersion             *int32
	Weights                 any
	SphereVersion           *int32
	Bits                    *int32
	Max                     *float64
	Min                     *float64
	BucketSize              *float64
	PartialFilterExpression any
	Collation               *Collation
	WildcardProjection      any
	Hidden                  *bool
}

type InsertManyOptions added in v0.7.1

type InsertManyOptions struct {
	BypassDocumentValidation *bool
	Ordered                  *bool
}

type InsertOneOptions added in v0.7.1

type InsertOneOptions struct {
	BypassDocumentValidation *bool
}

Options structs for various operations

type Interface

type Interface = types.Interface

Interface defines the common database operations supported by the framework

type ProjectionBuilder added in v0.7.1

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

func Projection added in v0.7.1

func Projection() ProjectionBuilder

Projection builder for specifying which fields to include/exclude

func (ProjectionBuilder) Build added in v0.7.1

func (pb ProjectionBuilder) Build() bson.M

func (ProjectionBuilder) ElemMatch added in v0.7.1

func (pb ProjectionBuilder) ElemMatch(field string, condition any) ProjectionBuilder

func (ProjectionBuilder) Exclude added in v0.7.1

func (pb ProjectionBuilder) Exclude(fields ...string) ProjectionBuilder

func (ProjectionBuilder) Include added in v0.7.1

func (pb ProjectionBuilder) Include(fields ...string) ProjectionBuilder

func (ProjectionBuilder) Slice added in v0.7.1

func (pb ProjectionBuilder) Slice(field string, limit int) ProjectionBuilder

func (ProjectionBuilder) SliceWithSkip added in v0.7.1

func (pb ProjectionBuilder) SliceWithSkip(field string, skip, limit int) ProjectionBuilder

type ReplaceOptions added in v0.7.1

type ReplaceOptions struct {
	BypassDocumentValidation *bool
	Upsert                   *bool
}

type SortBuilder added in v0.7.1

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

func Sort added in v0.7.1

func Sort() SortBuilder

Sort builder for specifying sort order

func (SortBuilder) Asc added in v0.7.1

func (sb SortBuilder) Asc(fields ...string) SortBuilder

func (SortBuilder) Build added in v0.7.1

func (sb SortBuilder) Build() bson.D

func (SortBuilder) Desc added in v0.7.1

func (sb SortBuilder) Desc(fields ...string) SortBuilder

type Statement added in v0.3.1

type Statement = types.Statement

Statement defines the interface for prepared statements

type Tx added in v0.3.1

type Tx = types.Tx

Tx defines the interface for database transactions

type UpdateBuilder added in v0.7.1

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

func Update added in v0.7.1

func Update() UpdateBuilder

Update builder for creating update documents

func (UpdateBuilder) AddToSet added in v0.7.1

func (ub UpdateBuilder) AddToSet(field string, value any) UpdateBuilder

func (UpdateBuilder) Build added in v0.7.1

func (ub UpdateBuilder) Build() bson.M

func (UpdateBuilder) CurrentDate added in v0.7.1

func (ub UpdateBuilder) CurrentDate(fields ...string) UpdateBuilder

func (UpdateBuilder) Inc added in v0.7.1

func (ub UpdateBuilder) Inc(field string, value any) UpdateBuilder

func (UpdateBuilder) Pull added in v0.7.1

func (ub UpdateBuilder) Pull(field string, condition any) UpdateBuilder

func (UpdateBuilder) Push added in v0.7.1

func (ub UpdateBuilder) Push(field string, value any) UpdateBuilder

func (UpdateBuilder) Set added in v0.7.1

func (ub UpdateBuilder) Set(field string, value any) UpdateBuilder

func (UpdateBuilder) Unset added in v0.7.1

func (ub UpdateBuilder) Unset(fields ...string) UpdateBuilder

type UpdateOptions added in v0.7.1

type UpdateOptions struct {
	ArrayFilters             []any
	BypassDocumentValidation *bool
	Upsert                   *bool
}

type WriteModel added in v0.7.1

type WriteModel interface {
	GetModel() any
}

WriteModel represents a write operation for bulk writes

Jump to

Keyboard shortcuts

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