Coder Social home page Coder Social logo

datafy's Introduction

Datafy

Summary

Datafy is a data mapping tool, heavily inspired by ActiveRecord. Datafy allows you to manipulate and query backend database tables, through Ruby class objects. Similar to ActiveRecord, these class models are interconnected through mapped associations.

Features

  • ::all - returns an array of all records in db table
  • ::find - finds a single record using primary key
  • #insert - inserts new row in db table
  • #update - updates row using id of record
  • #save - calls either insert/update depending on if record exists
  • #belongs_to - inputs include association name, and additional arguments, which then is turned into a method.
  • #has_many - inputs include association name, and additional arguments, which then is turned into a method.
  • #has_one_through - inputs include association name, source model and through model. It uses two belongs_to associations to generate a join query using foreign_key, primary_key and table_name. The return value is the associated object.

##Use

To use, download/clone this repository. Afterwards, head into pry, and load sample_model.rb. There, you can use Datafy methods on the seed data I have provided.

1. Clone this directory:

git clone https://github.com/szhu1026/Datafy

2. Load pry from the root folder and seed data, as shown below:

$ pry
[1] pry(main)> load 'test_models/sample_model.rb'
=> true

3. Search examples:

# Retrieve all plants where owner_id is 2.
Plant.where(owner_id: 2)

# Retrieve all plants.
Plant.all

# Find a single plant by an id.
Plant.find(1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.