|
1 | | -# SQL.rb (WIP/PoC) |
| 1 | +# sql-builder |
2 | 2 |
|
3 | | -A set of tools to generate SQL using AST transformations. |
4 | | - |
5 | | -The goal of this project is to provide a foundation for generating SQL that is |
6 | | -reusable for other Ruby libraries that need to translate their SQL-representation |
7 | | -into SQL strings. |
8 | | - |
9 | | -The idea is that SQL.rb ships with its own AST and a couple of tools to help |
10 | | -working with this AST. |
11 | | - |
12 | | -In example ActiveRecord **could do this**: |
13 | | - |
14 | | -``` ruby |
15 | | -ar_ast = User.select(:id, :name).where(name: 'Jane').to_ast |
16 | | -# s(:select, |
17 | | -# s(:fields, :id, :name), |
18 | | -# s(:from, 'users'), |
19 | | -# s(:where, |
20 | | -# s(:name, s(:eq, 'Jane')) |
21 | | -# ) |
22 | | -# ) |
23 | | - |
24 | | -sql_ast = ActiveRecord::SQL.call(User, ar_ast) |
25 | | -# s(:select, |
26 | | -# s(:fields, |
27 | | -# s(:id, 'id'), s(:id, 'name') |
28 | | -# ), |
29 | | -# s(:id, 'users'), |
30 | | -# s(:where, |
31 | | -# s(:eq, s(:id, 'name'), s(:string, 'Jane')) |
32 | | -# ) |
33 | | -# ) |
34 | | - |
35 | | -SQL[sql_ast] |
36 | | -# => SELECT "id", "name" FROM "users" WHERE "name" = 'Jane' |
37 | | -``` |
38 | | - |
39 | | -This project is in a PoC state and is heavily based on the experience and actual |
40 | | -code written initially for [ROM](https://github.com/rom-rb), specifically: |
41 | | - |
42 | | -* [dkubb/sql](https://github.com/dkubb/sql) - ast-based pure sql generator/parser |
43 | | -* [solnic/axiom-sql-generator](https://github.com/solnic/axiom-sql-generator) - which was an attempt to translate axiom ast into sql ast |
44 | | -* a ton of ast-processing-related work done by [mbj](https://github.com/mbj) for unparser and mutant gems |
45 | | - |
46 | | -## Installation |
47 | | - |
48 | | -Add this line to your application's Gemfile: |
49 | | - |
50 | | -```ruby |
51 | | -gem 'sql.rb' |
52 | | -``` |
53 | | - |
54 | | -And then execute: |
55 | | - |
56 | | - $ bundle |
57 | | - |
58 | | -Or install it yourself as: |
59 | | - |
60 | | - $ gem install sql.rb |
61 | | - |
62 | | -## Usage |
63 | | - |
64 | | -TODO: Write usage instructions here |
65 | | - |
66 | | -## Development |
67 | | - |
68 | | -After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. |
69 | | - |
70 | | -To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). |
71 | | - |
72 | | -## Contributing |
73 | | - |
74 | | -1. Fork it ( https://github.com/solnic/sql.rb/fork ) |
75 | | -2. Create your feature branch (`git checkout -b my-new-feature`) |
76 | | -3. Commit your changes (`git commit -am 'Add some feature'`) |
77 | | -4. Push to the branch (`git push origin my-new-feature`) |
78 | | -5. Create a new Pull Request |
| 3 | +TODO |
0 commit comments