<commit_before># Dao::Repository

[![Gem Version](https://badge.fury.io/rb/dao-repository.svg)](https://badge.fury.io/rb/dao-repository)
[![Build Status](https://travis-ci.org/dao-rb/dao-repository.svg?branch=master)](https://travis-ci.org/dao-rb/dao-repository)
[![Code Climate](https://codeclimate.com/github/dao-rb/dao-repository/badges/gpa.svg)](https://codeclimate.com/github/dao-rb/dao-repository)
[![Test Coverage](https://codeclimate.com/repos/5777e091620b91007d0001e3/badges/c01a62725cb50df7d9f9/coverage.svg)](https://codeclimate.com/repos/5777e091620b91007d0001e3/coverage)

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'dao-repository'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install dao-repository
    
## Built-in methods

Repositories in dao-rb are objects that allow you map your data into entities and save them through data gateway.

Basic methods of each repository:

1. `Repository.all` should return all data.
2. `Repository.find` should find entity with given id. You can return entity with its relations by adding a list of them into the second argument (`Repository.find(1, with: [:author, :comments])`), but your gateway should support eager loading. If entity was not found then method will raise an exception.
3. `Repository.find_by_id` also should find entity with given id, but if it was not found then method return `nil`.
4. `Repository.last` should return last entity. You can return entity with its relations by adding a list of them into the first argument (`Repository.last(with: [:author, :comments])`), but your gateway should support eager loading.
5. `Repository.count` should return count of entities.
6. `Repository.build` should build entity from data object.
7. `Repository.save` should save changes in entity.
8. `Repository.save_all` should save collection of entities.
9. `Repository.delete` should delete entity.
10. `Repository.delete_by_id` should delete entity by id.
11. `Repository.with_transaction(&block)` execute block in transaction if gateway support it.
12. `Repository.by_criteria` should return entities by given criteria.
13. `Repository.by_criteria_count` should return count of elements by given criteria.<commit_msg>readme added<commit_after># Dao::Repository

[![Gem Version](https://badge.fury.io/rb/dao-repository.svg)](https://badge.fury.io/rb/dao-repository)
[![Build Status](https://travis-ci.org/dao-rb/dao-repository.svg?branch=master)](https://travis-ci.org/dao-rb/dao-repository)
[![Code Climate](https://codeclimate.com/github/dao-rb/dao-repository/badges/gpa.svg)](https://codeclimate.com/github/dao-rb/dao-repository)
[![Test Coverage](https://codeclimate.com/repos/5777e091620b91007d0001e3/badges/c01a62725cb50df7d9f9/coverage.svg)](https://codeclimate.com/repos/5777e091620b91007d0001e3/coverage)

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'dao-repository'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install dao-repository
    
## Built-in methods

Repositories in dao-rb are objects that allow you map your data into entities and save them through data gateway.

Basic methods of each repository:

1. `Repository.all` should return all data.
2. `Repository.find` should find entity with given id. You can return entity with its relations by adding a list of them into the second argument (`Repository.find(1, with: [:author, :comments])`), but your gateway should support eager loading. If entity was not found then method will raise an exception.
3. `Repository.find_by_id` also should find entity with given id, but if it was not found then method return `nil`.
4. `Repository.last` should return last entity. You can return entity with its relations by adding a list of them into the first argument (`Repository.last(with: [:author, :comments])`), but your gateway should support eager loading.
5. `Repository.count` should return count of entities.
6. `Repository.build` should build entity from data object.
7. `Repository.save` should save changes in entity.
8. `Repository.save_all` should save collection of entities.
9. `Repository.delete` should delete entity.
10. `Repository.delete_by_id` should delete entity by id.
11. `Repository.with_transaction(&block)` execute block in transaction if gateway support it.
12. `Repository.with_lock(id, &block)` in transaction: lock db record with given id, execute block if gateway support it.
13. `Repository.by_criteria` should return entities by given criteria.
14. `Repository.by_criteria_count` should return count of elements by given criteria.
{'fraction_non_alphanumeric': 0.1086061131584652, 'fraction_numerical': 0.03078257099501409, 'mean_word_length': 4.961240310077519, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 16, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1133024', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1364, 'n_words': 483}