SMQL is a JSON-based query langauage similar to MQL. This gem convertes these querys to ActiveRecord.
Go to file
Denis Knauf 2fdc45d1d5 "self" and or
=============

This lines mean the same:

	User.smql :self => {:id => 1}
	User.smql :id => 1
	User.smql 'self.id' => 1
	User.smql 'self.self.self.self.id' => 1

self is like a reflection to itself.

Very userful if you need the new disjunction:

	User.smql :self => [{:surname => 'Mueller', :givenname => 'Michael'}, {:givenname => 'Horst', :surname => 'Schlemmer'}], :firm => {:name => 'Hotel an der Elbe'}

SmqlToAR::Column
----------------

Rejects every `self`,  so it is really like no self,
but you use `'self'` as like as a simple reflection.
You can ask,  if it is self via Column#self?

SmqlToAR::QueryBuilder
======================

joins:  The old `#join`. Renames because SmqlToAR::And and SmqlToAR::Or which has Array#join,
        so we cannot delegate `#join` to the QueryBuilder.

`#where`
--------

Now only one argument!  Needed for SmqlToAR::And and SmqlToAR::Or.

`#build` will generates LEFT OUTER JOINS now.  Needed for disjunctions.
The most queries will work like before.
Problems:

	User.smql :articles => {}

Before it will return all users with articles,  now it will return also users without articles.
If you want to have only all users with articles,  you ask:

	User.smql :articles => {:id => true}

Will fail if id IS NULL,  but this should not happen. ;)

`SmqlToAR::And` and `SmqlToAR::Or`
==================================

`SmqlToAR::QueryBuilder`-proxies.  QueryBuilder let them build where-clauses.
And will will produce a conjunction and  Or a disjunction of course.
They delegates all QueryBuilder-methods to QueryBuilder.
Only `#where` will stored local and `#build` will do it partial.

They have the same superclass: `SmqlToAR::SubBuilder`.

The small changes
=================

* `SmqlToAR.reload_library`:  Reloads SmqlToAR-lib.  Useful while development.
* `SmqlToAR::ConditionTypes#conditions`:  Return all Conditions.  `#try_parse` uses it.
* Some classes have a new `#inspect`.
* `SmqlToAR::ConditionTypes#Exists` / `NotExists`:
  `{:id => true}` / `{:id => false}`:
  This object has setted an id or not?  `#id` must exists as column of course!
	Uses `IS NOT NULL` and `IS NULL`.
2011-10-05 13:25:56 +02:00
lib "self" and or 2011-10-05 13:25:56 +02:00
.gitignore AR-through-reflections in query_builder; SmqlToAR.models returns the reflections-graph; limit, offset, sub-query "()" (not sub-conditions). unstable 0.3 2011-09-27 16:35:49 +02:00
AUTHORS init 2011-09-08 17:03:52 +02:00
LICENSE init 2011-09-08 17:03:52 +02:00
README.md readme: translationfixes 2011-09-09 00:05:43 +02:00
Rakefile AR-through-reflections in query_builder; SmqlToAR.models returns the reflections-graph; limit, offset, sub-query "()" (not sub-conditions). unstable 0.3 2011-09-27 16:35:49 +02:00
TODO init 2011-09-08 17:03:52 +02:00
VERSION AR-through-reflections in query_builder; SmqlToAR.models returns the reflections-graph; limit, offset, sub-query "()" (not sub-conditions). unstable 0.3 2011-09-27 16:35:49 +02:00

README.md

Idea

Similar to MQL: SMQL allows to perform queries on your database but in a JSON-based language.

This query language is SQL-injection-safe. However, expensive queries can slow down your machine.

Usage

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".

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]

Don't forget to add my gem to the Gemfile:

gem 'smql'