Gros-Câlin
Share your database queries via HTTP/JSON.
Installation
Install the gem:
$ gem install gros_calin
Depending on the drivers you'd like to use to connect your databases, you'll also have to install one or more of the following gems (see the Available drivers section below):
- mysql2 (MySQL)
- moped (MongoDB)
Usage
Create a configuration file (see the Configuration section below), then start the server:
$ gros_calin
If you want to place the process in the background:
$ gros_calin -d
By default, the server searches for a config.yml
file in the current
directory. To point to a specific location, use the -c
flag:
$ gros_calin -c /path/to/config.yml
The server binds to the port 3313
, use the -p
flag to change the port
number:
$ gros_calin -p 8080
To stop the server, hit Ctrl^C
or, if you placed it in the background:
$ gros_calin stop
Configuration
Configuration takes place in a YAML file. First declare your datasources using one of the available drivers, then list the queries you'd like to give a hug.
HTTP endpoints
- List available datasources:
http://localhost:3313/
- List available hugs for a datasource:
http://localhost:3313/<datasource>
- Query a specific hug:
http://localhost:3313/<datasource>/<hug>
Available drivers
MySQL
myapp_datasource:
driver: "mysql"
options:
host: "db.example.com"
username: "operator"
password: "secret"
database: "myapp"
hugs:
sign_ups: "SELECT count(id) AS sign_ups, country_code FROM users WHERE created_at > DATE_SUB( NOW(), INTERVAL 24 HOUR) GROUP by country_code;"
# another_datasource:
See the mysql2 client for a list of available connection options.
MongoDB
projects_datasource:
driver: "mongodb"
options:
hosts:
- replset1.example.com:27017
- replset2.example.com:27017
- replset3.example.com:27017
username: "operator"
password: "secret"
database: "myapp"
hugs:
issues: "db.projects.find( { score: { $lt: 3.8 } } ).sort(score: -1).toArray()"
status: "{ failures: db.projects.find( { status: 'failed' } ).count(), success: db.projects.find( { status: 'success' } ).count() }"
average_score: "db.builds.aggregate( { $group: { _id: '$project_id', builds: { $avg: '$score' } } }).result"
# another_datasource:
Frequently asked questions
Is it fast?
Well, it depends.
Does it scale?
It can serves up to a billion RPM (you'll have to rewrite it in Erlang, though).
"Gros-Câlin"?
Gros-Câlin (Big Cuddle) is named after the eponymous novel written by Romain Gary under the pen name Émile Ajar. In the book, M. Cousin, a statistician, lives with a python which hugs him tight and helps him cope with loneliness.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request