Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/junegunn/sql_helper


https://github.com/junegunn/sql_helper

Last synced: 28 days ago
JSON representation

Awesome Lists containing this project

README

        

# SQLHelper

A simplistic SQL generator extracted from [jdbc-helper](https://github.com/junegunn/jdbc-helper) gem.
This gem is not intended to be used independently outside the context of jdbc-helper.

## Example

```ruby
SQLHelper.select(
prepared: true,
table: 'mytable',
project: %w[a b c d e],
where: [
'z <> 100',
['y = ?', 200],
{
a: "hello 'world'",
b: (1..10),
c: (1...10),
d: ['abc', "'def'"],
e: { sql: 'sysdate' },
f: { not: nil },
g: { gt: 100 },
h: { lt: 100 },
i: { like: 'ABC%' },
j: { not: { like: 'ABC%' } },
k: { le: { sql: 'sysdate' } },
l: { ge: 100, le: 200 },
m: { not: [ 150, { ge: 100, le: 200 } ] },
n: nil,
o: { not: (1..10) },
p: { or: [{ gt: 100 }, { lt: 50 }] },
q: { like: ['ABC%', 'DEF%'] },
r: { or: [{ like: ['ABC%', 'DEF%'] }, { not: { like: 'XYZ%' } }] }
}
],
order: 'a desc',
limit: 10
)
```