diff --git a/README.md b/README.md index 2b3eb08..aafe060 100644 --- a/README.md +++ b/README.md @@ -3,22 +3,33 @@ # any_query -An ORM for any data source (SQL, CSV, TSV, REST API) +`any_query` is a versatile ORM designed to interface with various data sources including SQL, CSV, TSV, Fixed Length Text Format, and REST APIs. With any_query, you can write SQL-like queries and receive results as ActiveRecord-like objects. It supports operations like `select`, `limit`, and even `joins` across different data sources. + +## Features +* Unified Query Language: Write SQL-like queries for any supported data source. +* ActiveRecord-like Objects: Get results in a familiar format. +* Cross-data Source Joins: Combine data from different sources seamlessly. ## Installation -Add the gem to your Gemfile +To install `any_query`, add the gem to your Gemfile: ```ruby gem 'any_query' ``` -### Models +Then run: -Include `AnyQuery` and create adapters according to your needs: +```bash + bundle install +``` -```ruby +## Usage +### Setting up Models +To use `any_query`, include it in your model and set up the necessary adapters: + +```ruby class Invoice include AnyQuery @@ -68,7 +79,8 @@ class Customer end ``` -And write the query you need: +### Writing Queries +With your models set up, you can now write queries: ```ruby Invoice @@ -79,6 +91,42 @@ And write the query you need: ).to_a ``` +### Standalone Mode +You can also use `any_query` without models by creating a client directly: + +```ruby + sql_client = AnyQuery::Client.new( + adapter: :sql, + params: { + url: 'psql://user:password@localhost:5432/dbname', + primary_key: :id, + table: 'users' + } + ) + + csv_client = AnyQuery::Client.new( + adapter: :csv, + params: { + url: 'path/to/file.csv', + primary_key: :id, + fields: { + id: { type: :integer }, + user_id: { type: :integer }, + title: { type: :string }, + body: { type: :string }, + status: { type: :integer }, + created_at: { type: :datetime, format: '%Y-%m-%d %H:%M:%S' } + } + } + ) + + # Querying + csv_client + .joins(sql_client, :user_id, :id, into: :user, strategy: :full_scan) + .select(:number, :date, :customerNumber, :netAmount) + .to_a +``` + ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).