Skip to content

Commit

Permalink
Add features, limitations and relations sections to README
Browse files Browse the repository at this point in the history
  • Loading branch information
jirfag authored Sep 9, 2017
1 parent 7070775 commit 0ac3cf9
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ QuerySets for golang (go): typesafe, codegenerated ORM with GORM under the hood
* [Installation](#installation)
* [Usage](#usage)
* [Define models](#define-models)
* [Relation with GORM](#relation-with-gorm)
* [Create models](#create)
* [Select models](#select)
* [Update models](#update)
Expand All @@ -18,6 +19,9 @@ QuerySets for golang (go): typesafe, codegenerated ORM with GORM under the hood
* [Why not any ORM?](#why-not-any-orm)
* [Why not raw SQL queries?](#why-not-raw-sql-queries)
* [Why not go-kallax?](#why-not-go-kallax)
* [How it relates to another languages ORMs](#how-it-relates-to-another-languages-orms)
* [Features](#features)
* [Limitations](#limitations)


# Installation
Expand Down Expand Up @@ -88,6 +92,28 @@ See full autogenerated file [here](https://github.com/jirfag/go-queryset/blob/ma

Now you can use this queryset for creating/reading/updating/deleting. Let's take a lot at these operations.

## Relation with GORM
You can not embed `gorm.Model` into your model (e.g. if you don't need `DeletedAt` field), but you must use `*gorm.DB`
to properly work. Don't worry if you don't use GORM yet, it's [easy to create `*gorm.DB`](http://jinzhu.me/gorm/database.html#connecting-to-a-database):
```go
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
)

func getGormDB() *gorm.DB {
db, err := gorm.Open("mysql", "user:password@/dbname?charset=utf8&parseTime=True&loc=Local")
// ...
}
```

If you already use another ORM or raw `sql.DB`, you can reuse your `sql.DB` object (to reuse connections pool):
```go
var sqlDB *sql.DB = getSQLDBFromAnotherORM()
var gormDB *gorm.DB
gormDB, err = gorm.Open("mysql", sqlDB)
```

## Create
```go
u := User{
Expand Down Expand Up @@ -370,3 +396,18 @@ No type-safety, a lot of boilerplate code.
## Why not [go-kallax](https://github.com/src-d/go-kallax)?
1. It works only with PostgreSQL. Go-queryset supports mysql, postgresql, sqlite, mssql etc (all that gorm supports).
2. Lacks simplier model updating interface

## How it relates to another languages ORMs
QuerySet pattern is similar to:
* [Django QuerySet](https://docs.djangoproject.com/en/dev/ref/models/querysets/), but better than it because of type-safety (Python)
* [Rails Active Record and it's scopes](http://guides.rubyonrails.org/active_record_querying.html#scopes), but better than it because of type-safety (Ruby)

# Features
* 100% typesafe: there is no one method with `interface{}` arguments.
* QuerySet pattern allows to reuse queries by defining [custom methods](https://github.com/jirfag/go-queryset/blob/master/examples/comparison/gorm4/gorm4.go#L30) on it.
* Supports all DBMS that GORM supports: MySQL, PostgreSQL, Sqlite3, SQL Server.
* Supports creating, selecting, updating, deleting of objects.

# Limitations
* Joins aren't supported
* Struct tags aren't supported

0 comments on commit 0ac3cf9

Please sign in to comment.