GithubHelp home page GithubHelp logo

dynamicbase's Introduction

DynamicBase

DynamicBase is a lightweight object-relational mapping tool built with Ruby. By creating a subclass of the Base class, existing tables in the database are mapped to these new classes.

Example Usage

Using the sample database as an example, one can retrieve the NYC attractions in the Bronx by running Borough.first.sights. To change a property, for example the name, one can simply type

bronx = Borough.first
bronx.name = 'The Bronx'
bronx.save

Features

Base

Searchable

Associations

Base

all

Will return an array of all entries in the database for the specified table.

Example: Borough.all

first

Will return the first database entry for the specified table (ordered by id).

Example: Borough.first

last

Will return the last database entry for the specified table (ordered by id).

Example: Borough.last

find(id)

Will return the entry in the database with the id matching the argument.

Example: Borough.find(4)

new

Creates a new Base object (which can be modified and then update or insert intothe database with the save method below)

Example: Borough.new

save

Depending on if entry exists in database, will either update or insert into database.

Example:

borough = Borough.new
borough.name = "Queens"
borough.save

Searchable

where

Returns the results of a SQL query based on the hash parameters passed in as arguments.

Example: Borough.where(name: "Manhattan")

Associations

belongs_to

Will return base object with the child associated with the selected object.

Example: Neighborhood.first.borough

has_many

Will return base object with the parent associated with the selected object.

Example: Borough.first.neighborhoods

has_one_through

Will return base object with the grandparent associated with the selected object.

Example: Sight.first.borough

Demo

A sample database is included. To run simply clone this repo and open with pry or IRB with the load 'demo/nyc.rb' command.

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.