nosql

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 10 Imported by: 0

README

nosql — MongoDB CRUD wrapper

import "github.com/downsized-devs/sdk-go/nosql"

Stability: Beta — no tests in package. See STABILITY.md.

Thin wrapper around the official MongoDB Go driver. Provides typed CRUD without exposing the driver's full surface.

Features

  • Find, FindOne, InsertOne, UpdateOne, UpdateMany
  • Close for clean shutdown

Installation

go get github.com/downsized-devs/sdk-go/nosql

Quick Start

db := nosql.Init(nosql.Config{
    URI:      "mongodb://localhost:27017",
    Database: "app",
}, log)
defer db.Close(context.Background())

_ = db.InsertOne(ctx, "users", bson.M{"_id": "alice", "name": "Alice"})
var u User
_ = db.FindOne(ctx, "users", bson.M{"_id": "alice"}, &u)

API Reference

Symbol Signature
Init func Init(cfg Config, log logger.Interface) Interface
Interface.Close (ctx) error
Interface.Find (ctx, collection string, filter, dest any) error
Interface.FindOne (ctx, collection string, filter, dest any) error
Interface.InsertOne (ctx, collection string, doc any) error
Interface.UpdateOne (ctx, collection string, filter, update any) error
Interface.UpdateMany (ctx, collection string, filter, update any) error

Configuration

Field Description
URI Mongo connection string.
Database Default database name.

Error Handling

Wraps with codes nosql-range codes (1400–1499).

Dependencies

  • Internal: codes, errors, logger
  • External: go.mongodb.org/mongo-driver/mongo, .../mongo/options

Testing

No tests yet. Use mongomock or run against a local Mongo container.

go test ./nosql/...

Contributing

See CONTRIBUTING.md. Test coverage gates promotion to Stable.

  • sql — relational alternative.
  • redis — cache layer in front of either.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	WaitingTime int
	DBUrl       string
	DB          string
}

type Interface

type Interface interface {
	Close(ctx context.Context) error
	Find(ctx context.Context, collection string, entity interface{}, filter interface{}, opts ...*options.FindOptions) error
	FindOne(ctx context.Context, collection string, dest interface{}, filter interface{}, opts ...*options.FindOneOptions) error
	InsertOne(ctx context.Context, collection string, data interface{}) (*mongo.InsertOneResult, error)
	UpdateOne(ctx context.Context, collection string, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
	UpdateMany(ctx context.Context, collection string, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
}

func Init

func Init(cfg Config, log logger.Interface) Interface

Jump to

Keyboard shortcuts

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