Skip to content

Commit

Permalink
feat(README): improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ProGM committed Sep 21, 2023
1 parent 299f1a6 commit d6377fb
Showing 1 changed file with 54 additions and 6 deletions.
60 changes: 54 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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).
Expand Down

0 comments on commit d6377fb

Please sign in to comment.