Giter VIP home page Giter VIP logo

goxes's Introduction

Goxes

Object-Relational Mapping experiment for golang (Redesign Boxes)

Box

Example 1.1. Create Box
transactionsBox := boxes.New(func(i interface{}) map[string]interface{} {
        transaction := i.(TransactionModel)
        m := make(map[string]interface{})
        m["id"] = transaction.GetId()
        m["date"] = transaction.GetDate()
        m["count"] = transaction.GetCount()
        return m
    }, func (m map[string]interface{}) interface{} {
        return &Transaction{
            int(m["id"].(float64)),
            int64(m["date"].(float64)),
            int(m["count"].(float64)),
        }
    }, "/home/user/stan/goxes/transactionsbox")
Example 1.2. Put objects to Box
transactionsBox.Add(&Transaction{1, 100, 123},
					&Transaction{2, 58, 124},
					&Transaction{3, -45, 125},
					&Transaction{4, 23, 126},
					&Transaction{5, -78, 127})
Example 1.3. Get list objects from Box
for i, v := range transactionsBox.GetAll() {
    transaction := v.(*Transaction)
    fmt.Println(i, ")", "count:", transaction.GetCount())
}
Example 1.4. Get list objects from Box with query
for i, v := range transactionsBox.Query(func(e interface{}) bool {
    transaction := e.(*Transaction)
    return transaction.GetCount() < 75
}) {
    transaction := v.(*Transaction)
    fmt.Println(i, ")", "count:", transaction.GetCount())
}
Example 1.5. Replace object in Box
transactionsBox.Replace(func(e interface{}) bool {
    transaction := e.(*Transaction)
    return transaction.GetId() == 3
}, &Transaction{3, 23, 12})
Example 1.6. Remove object from Box
transactionsBox.RemoveFirst(func(e interface{}) bool {
    transaction := e.(*Transaction)
    return transaction.GetId() == 4
})

goxes's People

Contributors

kepocnhh avatar

Watchers

James Cloos avatar  avatar

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.