KO
|
EN
gitlite — search
Search
#python
#java
#python3
#arduino
#golang
#machine-learning
#rust
#html
#flask
#javascript
#seismology
#nodejs
orange
★ 22
Open GitHub ↗
A lightweight Object Relational Mapper for Go
Download README (.md)
Explore Similar Repositories
brew-cask-replacer
:
No description available.
RoundProgressTextView
:
TextView with Round Pogress
ticket-auth
:
No description available.
stabping
:
Continuously monitor your connection/ISP's latency & speed and view them in interactive charts
dockerfile
:
Collection of Docker recipes
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
orange
?
Download (.md)
# Orange [](https://godoc.org/github.com/gernest/orange)[](https://coveralls.io/github/gernest/orange?branch=master) [](https://travis-ci.org/gernest/orange) Orange is a lightweight, simple Object relational Mapper for Golang. Orange offers a simple API for building meaningful database queries, and good abstractions on top of standard database/sq Orange is inspired by [gorm](https://github.com/jinzhu/gorm) # Features * Simple API * Fast * Auto migrations * Multiple database support( currently only postgresql but mysql and sqlite are work in progress) * Zero dependency( only the standard library) * Simple SQL query building API # Motivation This is my understanding of Object Relational Mapping with Golang. Instead of writing a blog post, I took the liberty to implement `orange`. It has almost all the things you might need to interact with databases with Golang. The source code is geared toward people who want to harness the power of Go. There is a lot of myths around reflections in Go, I have almost used all the techniques you will need to master reflections. THIS IS NOT FOR PRODUCTION USE, unless you know what you are doing in which case your contribution is welcome. # Installation ```bash go get github.com/gernest/orange ``` # Usage The following is a simple example to showcase the power of orange, for comprehensive API please check [ The Orange Documentation](https://godoc.org/github.com/gernest/orange) ```go package orange_test import ( "fmt" "github.com/gernest/orange" // Include the driver for your database _ "github.com/lib/pq" ) type golangster struct { ID int64 Name string } func Example() { // Open a database connection connectionSTring := "user=postgres dbname=orange_test sslmode=disable" db, err := orange.Open("postgres", connectionSTring) if err != nil { panic(err) } // Register the structs that you want to map to err := db.Register(&golangster{}) if err != nil { panic(err) } // Do database migrations( tables will be created if they dont exist err = db.Automigrate() if err != nil { panic(err) } // Make sure we are connected to the database we want name := db.CurrentDatabase() fmt.Println(name) // on my case it is orange_test // Insert a new record into the database err = db.Create(&golangster{Name: "hello"}) if err != nil { panic(err) } // count the number of records var count int db.Count("*").Bind(&count) fmt.Println(count) // in my case 1 // Retrieve a a record with name hello result := golangster{} db.Find(&result, &golangster{Name: "hello"}) fmt.Println(result) // on my case { 1, "hello"} } ``` # TODO list These are some of the things I will hope to add when I get time * Delete record * Support mysql * support sqlite * more comprehensive tests * improve perfomace * talk about orange # Contributing Contributions of all kinds are welcome # Author Geofrey Ernest [twitter @gernesti](https://twitter.com/gernesti) # Licence MIT see [LICENCE](LICENCE)