• Stars
    star
    4
  • Rank 3,304,323 (Top 66 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 5 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple query interface for pulling deeply nested data from records.

Ruby

ActiveRecord::Pull::Alpha

A simple query interface for pulling deeply nested data from records.

Synopsis

  class Survey < ActiveRecord::Base
    has_many :questions
    has_many :responses
  end

  class Question < ActiveRecord::Base
    has_many :answers
  end

  class Answer < ActiveRecord::Base
    belongs_to :reply
    belongs_to :question
  end

  class Response < ActiveRecord::Base
    belongs_to :survey
    has_many :answers
  end

  Survey.find(34).pull(:name, questions: [:text, answers: [:created_at]])
  Response.where('created_at < ?', Date.new(2018, 7, 5)).pull({ survey: :name }, { answers: :value }) 

Why?

When using an SQL database modeling trees and ontologies is an exercise in relational database design. Unfortunately, when dealing with deeply nested and overlapping data (e.g. medical records and social graphs) trees and ontologies won't do. We need to model graphs, a much more sparsely structured data model, but this leads to very complex (or sparse) table structures and very complex SQL queries.

Alternatives to SQL databases like Datomic, RDF and graph databases resolve this problem in the general case, but sometimes those solutions are not a viable option for one reason or another. This gem attempts to provide some of the convenience of these solutions as an extension to ActiveRecord. As a bonus it makes querying trees and ontologies simple too!

Pull Syntax

The pull syntax is inspired by the pull syntax that is used in Datomic.

Installation

Add this line to your application's Gemfile:

gem 'activerecord-pull-alpha'

And then execute:

$ bundle

Or install it yourself as:

$ gem install activerecord-pull-alpha

See Also

License

The gem is available as open source under the terms of the MIT License.

More Repositories

1

invokable

Objects are functions! Treat any Object or Class as a Proc (like Enumerable but for Procs).
Ruby
43
star
2

mini-levenshtein

Simple, fast Levenshtein distance and similarity ratio for Ruby
C
27
star
3

activerecord-setops

Union, Intersect, and Difference set operations for ActiveRecord (also, SQL's UnionAll).
Ruby
21
star
4

magbot

A CLI application for fetching media from jw.org feeds
Perl
9
star
5

zera-5

A light-weight Clojure interpreter
JavaScript
8
star
6

contracts-gen

Generate data from contracts
Ruby
2
star
7

dragnet

A work-in-progress system for programmable surveys, and forms.
Ruby
2
star
8

ALJAFP

A Little Java, A Few Patterns
Java
1
star
9

piglatin

Pig Latin translator
Perl
1
star
10

cantor

Relational Algebra and Reporting
Ruby
1
star
11

atomjs

Clojure Atoms for Javascript. Shared, synchronous, independent state. A fork of https://github.com/cjohansen/js-atom.
JavaScript
1
star
12

sinatra-rest-service-auth

Ruby
1
star
13

sleepr

Stop hacking and get some sleep
Perl
1
star
14

connect4

JavaScript
1
star
15

tether

Ruby
1
star
16

tetris.js

An (incomplete) tetris clone
JavaScript
1
star
17

wonderscript-alpha

A lisp for the web
TypeScript
1
star
18

periscope

A Perl Module for viewing sites through a periscope
Perl
1
star
19

pandora-periscope

A Periscope for Pandora
Perl
1
star
20

java-posix

POSIX for Java a clone (for posterity, I have no intention of maintaining this) imported from tarball found here: http://www.bmsi.com/java/posix/index.html
Java
1
star
21

Pudu

A light-weight Moose-like object system that makes it easy to create encapsulated, immutable objects
Perl
1
star
22

Makakilo-Elementary

Ruby
1
star
23

sleepr-preferences

Preferences dialog for sleepr
Python
1
star
24

yugo

An experimental tool for converting legacy ColdFusion applications into Ruby / Rack applications.
Ruby
1
star
25

talks

1
star
26

asdf-vm.el

asdf-vm integration for Emacs
Emacs Lisp
1
star
27

kigo

Ruby is already pretty lispy let's take it the rest of the way.
Ruby
1
star
28

rubygems

A fork to add offline installation features, all changes are in offline branch
Ruby
1
star