GithubHelp home page GithubHelp logo

lucius's Introduction

Lucius

CRUD for mgo - golang mongodb driver Package for quick plug'n play use of mgo - mongodb driver for golang language.

Provides functions for basic manipulation of mongodb documents in CRUD (Create, Read, Update, Delete) pattern.

Install

go get github.com/vedrans/lucius.git

Usage

Before using db host and name needs to be setup with public SetDB function which accepts two string parameters (db host and name) or same can be done using two separate public functions SetDBHost and SetDBName.

Create

Create function accepts document in bson.M format (from labix.org/v2/mgo/bson package) and collection name as string parameter. It returns error if document couldn't be saved for some reason or nil otherwise.

FindByID

FindByID function finds one document that is matching given ID and collection name. Function accepts two parameters: ID (in bson.ObjectId type) and collection name (in string type) and returns two parameters document in bson.M format and error if query failed, nil otherwise.

FindBy

FindBy function finds one document that is matching given condition and collection name. This function accepts condition writen in bson.M format as first parameter and collection name as second parameter. It returns two parameters: document in bson.M format and error if query failed, nil otherwise.

FindAll

FindAll function returns all documents in specific collection as an array of bson.M objects as first parameter on return. It requests collection name as string and returns error as second parameter or nil if query was successful.

Update

Update function replaces matched document with provided. It accepts condition as bson.M, new document as bson.M and collection name as string. It returns error if query failed, nil otherwise.

Patch

As difference from Update function, Patch just updates matched document with provided. It accepts condition as bson.M, update as bson.M and collection name as string. It returns error if query failed, nil otherwise. It basically is merging existing document with provided update. If some parameter exists in both documents update one is replacing existing one, if existing document doesn't have parameter update document have it will be simply added.

Delete

Delete function deletes matched document from collection. It accepts id of document in bson.ObjectId format and collection name as string and returns error if query fails otherwise nil.

Licence

This package is covered by GNU GENERAL PUBLIC LICENSE Version 3 licence.

Contributing

If you would like to improve this package all pull requests are very welcome as long as covered by test.

lucius's People

Contributors

vsrc avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

a233894432

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.