From 0ac3cf999c787efc04463970a91c8e8c4c54ab24 Mon Sep 17 00:00:00 2001 From: Isaev Denis Date: Sat, 9 Sep 2017 23:23:45 +0300 Subject: [PATCH] Add features, limitations and relations sections to README --- README.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/README.md b/README.md index 5cce542..c897b97 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 @@ -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{ @@ -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