Project

puffs

0.0
No commit activity in last 3 years
No release in over 3 years
Make simple apps the Rails way, but with less overhead.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 10.0
~> 3.0

Runtime

>= 4.2.5.1, ~> 4.2
~> 0.7
~> 0.18
~> 0.10.3
>= 1.6.4, ~> 1.6
~> 0.19
 Project Readme

Puffs

Puffs is a lightweight MVC with a built-in ORM that allows you to make updates to a Postgres database without writing much SQL code. Sounds a little like Rails? Well, let's say Puffs was inspired by Rails ;).

How To Do Puffs

  1. Things you need:
  • Ruby
  • Postgres
  1. Open command line, enter the following:
  2. gem install puffs
  3. `puffs new [name of your app]``
  4. puffs db create
  5. You're all set!

Command Line Interface

Enter 'puffs' into the command line with no arguments to see the full list of commands, or just read them below:

  • `puffs new [app name]``
  • puffs server
  • puffs generate
    • model [model name]
    • controller [controller name]
    • migration [migration name]
  • puffs db
    • create
    • migrate
    • seed
    • reset

Demo App

As you explore this document, you may find it helpful to reference the SamplePuffsApp on the puffs Github repo to see how everything connects.

The Puffs ORM

Puffs' object relational mapping is inspired by Rails' ActiveRecord. It converts tables in a Postgres database into instances of the Puffs::SQLObject class.

Puffs::SQLObject is a very lightweight version of ActiveRecord::Base. It's a great way to use ActiveRecord::Base's CRUD methods and associations without all the extra overhead.

Puff::SQLRelation imitates the behavior of ActiveRecord::Relation, making sure no unnecessary queries are made to the DB.

###All of your favorite methods are present, including:

  • #create
  • #find
  • #all
  • #update
  • #destroy

###Also builds Rails table associations:

  • ::belongs_to
  • ::has_many
  • ::has_one_through
  • ::has_many_through

##Puffs::SQLRelation Has the basic functionality of ActiveRecord::Relation, allowing us to order and search DB entries with minimal querying.

All methods are lazy and stackable. Queries are only fired when SQLRelation#load is called or when the relation is coerced into an Array.

###Methods included:

  • ::all
  • ::where
  • ::includes
  • ::find
  • ::order
  • ::limit
  • ::count
  • ::first
  • ::last

###Eager loading reduces queries

  • Preload has_many and belongs_to associations by calling SQLObject::includes
    • Lazy and chainable.
    • Reduces your DB queries from (n + 1) to 2.

Database

The Puffs commands prefixed with 'db' interact with the Puffs Postgres database.

  • puffs db create drops any Postgres DB named 'Puffs' and creates a new, empty one.
  • puffs db migrate finds and any SQL files under db/migrate that have not been migrated and copies them into the DB.
  • puffs db seed calls Seed::populate in db/seeds.rb, allowing you to quickly reset your DB to a seed file while in development.
  • puffs db reset executes all three of the above commands, saving you time and energy!

Migrations

Entering puffs generate (or puffs g) migration [migration name] in the command line will create a time-stamped SQL file under db/migrations. Write SQL in here to stage changes in the DB (add, drop, or change tables), and puffs db migrate to implement them.

NB: To reverse a migration that has been run, you must generate a new migration that undoes the changes. Deleting the original migration will do nothing.

Puffs::ControllerBase

Puffs::ControllerBase connects your models to your routes, allowing access to the DB through html.erb views. It's how Puffs takes over the Web.

Router

Routes live in config/routes.rb. New routes are written using Regex. Open a server connection with the puffs server command.

Puffs Console

Access your DB with Puffs::SQLObject methods by simply entering require 'puffs' in Pry (or IRB).

Todos

  • Flash / Flash.now
  • CSRF Form Authenticity Token
  • Production Database (push to Heroku)