2011-09-08 17:03:52 +02:00
|
|
|
Idea
|
|
|
|
====
|
|
|
|
|
2011-09-09 00:05:43 +02:00
|
|
|
Similar to MQL: SMQL allows to perform queries on your database but in a JSON-based language.
|
2011-09-08 17:03:52 +02:00
|
|
|
|
|
|
|
This query language is SQL-injection-safe.
|
2011-09-09 00:02:24 +02:00
|
|
|
However, expensive queries can slow down your machine.
|
2011-09-08 17:03:52 +02:00
|
|
|
|
|
|
|
Usage
|
|
|
|
=====
|
|
|
|
|
2011-09-09 00:02:24 +02:00
|
|
|
Example: An easy query in ruby:
|
|
|
|
User is a ActiveRecord-Model and has a column username.
|
|
|
|
We want to find all _users_ _where_ _username_ = _"auser"_.
|
2011-09-08 17:03:52 +02:00
|
|
|
|
|
|
|
require 'smql'
|
|
|
|
|
|
|
|
SmqlToAR.to_ar User, '{"username": "auser"}' # Query in JSON
|
|
|
|
SmqlToAR.to_ar User, username: "auser" # Query in Ruby
|
|
|
|
|
|
|
|
In Rails:
|
|
|
|
|
|
|
|
SmqlToAR.to_ar User, params[:smql]
|
|
|
|
|
2011-09-09 00:02:24 +02:00
|
|
|
Don't forget to add my gem to the _Gemfile_:
|
2011-09-08 17:03:52 +02:00
|
|
|
|
|
|
|
gem 'smql'
|