diff --git a/README.md b/README.md index c73f56fe5171d1c79a7ea4516167e6a38d99f19e..ba79f2b8fe8141d5bf81c767cd524eb2eb628632 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ gosexy is a general purpose framework for Go that provides [sugar](http://en.wik ### Before pulling the source -Make sure you have the ``git``, ``hg`` (mercurial) and ``bzr`` (bazaar) source control systems installed on your system, those packages are available for many linux distros and also in [homebrew](http://mxcl.github.com/homebrew/) for OSX. You'll also require ``sqlite3`` and ``pkg-config``. All those packages are required for building some third party wrappers. +Make sure you have the ``git``, ``hg`` (mercurial) and ``bzr`` (bazaar) source control systems installed on your system, those packages are available for many linux distros and also in [homebrew](http://mxcl.github.com/homebrew/) for OSX. You'll also require ``sqlite3`` and ``pkg-config``. All those packages are required for building some third party dependencies. -Here's how you would install on OSX using brew +Here's how you would install them all on OSX using brew $ brew install git $ brew install hg @@ -16,13 +16,13 @@ Here's how you would install on OSX using brew $ brew install sqlite3 $ brew install pkg-config -Or, let's suppose you want to get them all in ArchLinux +Or, let's suppose you want to bring them to ArchLinux # sudo pacman -S mercurial bzr sqlite3 git pkg-config ### Using gosexy in your Go program -First, get the source using go +First, get the source using ``go`` $ go get github.com/xiam/gosexy @@ -32,7 +32,7 @@ Then import ``gosexy`` into your actual source code ## Sugar wrappers -* [gosexy/db](https://github.com/xiam/gosexy/tree/master/db) - A wrapper of database/sql, mgo and friends for querying to MongoDB, MySQL, PostgreSQL or SQLite3 databases in a consistent way. +* [gosexy/db](https://github.com/xiam/gosexy/tree/master/db) - A wrapper of [database/sql](http://golang.org/pkg/database/sql), [mgo](http://launchpad.net/mgo) and friends for querying to MongoDB, MySQL, PostgreSQL or SQLite3 databases over a single, consistent interface. * [gosexy/yaml](https://github.com/xiam/gosexy/tree/master/yaml) - A wrapper of [goyaml](http://launchpad.net/goyaml) for working with [YAML](http://www.yaml.org) formatted files. ## Sugar types diff --git a/db/README.md b/db/README.md index 18ea10312ca4cbf9a56d59533e1460136218393b..d35a6400df25d3e5d6e7f4897dc6dbfb77b3d16c 100644 --- a/db/README.md +++ b/db/README.md @@ -4,6 +4,8 @@ This package is a wrapper of [mgo](http://launchpad.net/mgo), [database/sql](htt ## Installation +Please read docs on the [gosexy](https://github.com/xiam/gosexy) package before rushing to install ``gosexy/db`` + $ go get github.com/xiam/gosexy/db ## Available interfaces @@ -19,16 +21,16 @@ For the sake of ease, it is recommended that you import ``github.com/xiam/gosexy import . "github.com/xiam/gosexy/db" -Each database has its very specific way of doing the same task, the interface and methods are the same for any of them. - -Be aware that all the examples in this page are shown without prefixes. +All the examples in this page are shown without prefixes. -### Setting up a database +### Setting up a database source -The first step is to choose a driver and set up the connection, this is how it would be done using ``MysqlSession`` +The first step is to choose a driver and set up the connection using a ``DataSource``, this is how it would be done using ``MysqlSession`` sess := MysqlSession(DataSource{Host: "localhost", Database: "test", User: "myuser", Password: "mypass"}) +Please note that each database has its very specific way of doing the same task, but the interface and methods of ``gosexy/db`` are the same for any of them. + The ``DataSource`` is a generic structure than can store connection values in a consistent way. // Connection and authentication data. @@ -44,7 +46,7 @@ You may use other drivers to setup a connection, available drivers are ``MysqlSe ### Connecting to the database -Use your recently configured ``Database`` to request the driver to actually connect to the selected database. +Use your recently configured ``Database`` to request the driver to actually connect to the selected database using ``Database.Open()``. // Setting up database. sess := MysqlSession(DataSource{Host: "localhost", Database: "test", User: "myuser", Password: "mypass"}) @@ -150,42 +152,41 @@ Return the first Item of the collection that matches all the provided conditions }, ) -You can use relations in your definition +You can also use relations in your definition - // Relations example. - collection.FindAll( - // One-to-one relation with the table "places". - Relate{ - "lives_in": On{ - session.Collection("places"), - // Relates rows of the table "places" where place.code_id = collection.place_code_id. - Where{"code_id": "{place_code_id}"}, - }, - }, - RelateAll{ - // One-to-many relation with the table "children". - "has_children": On{ - session.Collection("children"), - // Relates rows of the table "children" where children.parent_id = collection.id - Where{"parent_id": "{id}"}, + collection.FindAll( + // One-to-one relation with the table "places". + Relate{ + "lives_in": On{ + session.Collection("places"), + // Relates rows of the table "places" where place.code_id = collection.place_code_id. + Where{"code_id": "{place_code_id}"}, + }, }, - // One-to-many relation with the table "visits". - "has_visited": On{ - session.Collection("visits"), - // Relates rows of the table "visits" where visits.person_id = collection.id - Where{"person_id": "{id}"}, - // A nested relation - Relate{ - // Relates rows of the table "places" with the "visits" table. - "place": On{ - session.Collection("places"), - // Where places.id = visits.place_id - Where{"id": "{place_id}"}, + RelateAll{ + // One-to-many relation with the table "children". + "has_children": On{ + session.Collection("children"), + // Relates rows of the table "children" where children.parent_id = collection.id + Where{"parent_id": "{id}"}, + }, + // One-to-many relation with the table "visits". + "has_visited": On{ + session.Collection("visits"), + // Relates rows of the table "visits" where visits.person_id = collection.id + Where{"person_id": "{id}"}, + // A nested relation + Relate{ + // Relates rows of the table "places" with the "visits" table. + "place": On{ + session.Collection("places"), + // Where places.id = visits.place_id + Where{"id": "{place_id}"}, + }, }, }, }, - }, - ) + ) #### Collection.FindAll(...interface{}) []Item