All Projects → twopoint718 → Reactive_record

twopoint718 / Reactive_record

Licence: mit
Generate ActiveRecord models for a pre-existing Postgres db

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Reactive record

Scenic
Scenic is maintained by Derek Prior, Caleb Hearth, and you, our contributors.
Stars: ✭ 2,856 (+2063.64%)
Mutual labels:  sql, database, postgres, rails
Rein
Database constraints made easy for ActiveRecord.
Stars: ✭ 657 (+397.73%)
Mutual labels:  database, postgres, rails, constraints
Goqu
SQL builder and query library for golang
Stars: ✭ 984 (+645.45%)
Mutual labels:  sql, database, postgres
Niklick
Rails Versioned API solution template for hipsters! (Ruby, Ruby on Rails, REST API, GraphQL, Docker, RSpec, Devise, Postgress DB)
Stars: ✭ 39 (-70.45%)
Mutual labels:  database, postgres, rails
Ebean
Ebean ORM
Stars: ✭ 1,172 (+787.88%)
Mutual labels:  sql, database, postgres
Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 7,712 (+5742.42%)
Mutual labels:  sql, database, postgres
Efcore.pg
Entity Framework Core provider for PostgreSQL
Stars: ✭ 838 (+534.85%)
Mutual labels:  sql, database, postgres
Squid
🦑 Provides SQL tagged template strings and schema definition functions.
Stars: ✭ 57 (-56.82%)
Mutual labels:  sql, database, postgres
Gnorm
A database-first code generator for any language
Stars: ✭ 415 (+214.39%)
Mutual labels:  sql, database, postgres
Graphjin
GraphJin - Build APIs in 5 minutes with GraphQL. An instant GraphQL to SQL compiler.
Stars: ✭ 1,264 (+857.58%)
Mutual labels:  sql, database, rails
Evolutility Server Node
Model-driven REST or GraphQL backend for CRUD and more, written in Javascript, using Node.js, Express, and PostgreSQL.
Stars: ✭ 84 (-36.36%)
Mutual labels:  sql, database, postgres
Electrocrud
Database CRUD Application Built on Electron | MySQL, Postgres, SQLite
Stars: ✭ 1,267 (+859.85%)
Mutual labels:  sql, database, postgres
Citus
Distributed PostgreSQL as an extension
Stars: ✭ 5,580 (+4127.27%)
Mutual labels:  sql, database, postgres
Node Pg Migrate
Node.js database migration management for Postgresql
Stars: ✭ 838 (+534.85%)
Mutual labels:  sql, database, postgres
Zero downtime migrations
Zero downtime migrations with ActiveRecord 3+ and PostgreSQL
Stars: ✭ 513 (+288.64%)
Mutual labels:  database, postgres, rails
Cosyan
Transactional SQL based RDBMS with sophisticated multi table constraint logic.
Stars: ✭ 45 (-65.91%)
Mutual labels:  sql, database, constraints
Activerecord Clean Db Structure
Automatic cleanup for the Rails db/structure.sql file (ActiveRecord/PostgreSQL)
Stars: ✭ 101 (-23.48%)
Mutual labels:  database, postgres, rails
Ansible Role Postgresql
Ansible Role - PostgreSQL
Stars: ✭ 310 (+134.85%)
Mutual labels:  sql, database, postgres
Jet
Type safe SQL builder with code generation and automatic query result data mapping
Stars: ✭ 373 (+182.58%)
Mutual labels:  sql, database, postgres
Go Dberror
parsing postgres errors
Stars: ✭ 78 (-40.91%)
Mutual labels:  database, postgres, constraints

Reactive record logo
Logo design: Kelly Rauwerdink, @missingdink.

Gem Version

Generates ActiveRecord models to fit a pre-existing Postgres database. Now you can use Rails with the db schema you always wanted. It's your convention over configuration.

Why?

  1. Your app is specific to Postgres and proud of it. You use the mature declarative data validation that only a real database can provide.
  2. You have inherited a database or are more comfortable creating one yourself.
  3. You're a grown-ass DBA who doesn't want to speak ORM baby-talk.

Features

  • Fully automatic. It just works.
  • Creates a model for every table.
  • Creates a comprehensive initial migration.
  • Declares key-, uniqueness-, and presence-constraints.
  • Creates associations.
  • Adds custom validation methods for CHECK constraints.

Usage

Already familiar with Rails?

  • Set up a postgres db normally
  • Set config.active_record.schema_format = :sql to use a SQL schema.rb
  • After you have migrated up a table, use rails generate reactive_record:install
  • Go examine your generated models

Want more details?

First Include the reactive_record gem in your project's Gemfile. Oh by the way, you'll have to use postgres in your project. Setting up Rails for use with postgres is a bit outside the scope of this document. Please see [Configuring a Database] (http://guides.rubyonrails.org/configuring.html#configuring-a-database) for what you need to do.

gem 'reactive_record'

Bundle to include the library

$ bundle

Next Tell ActiveRecord to go into beast-mode. Edit your config/application.rb, adding this line to use sql as the schema format:

module YourApp
  class Application < Rails::Application
    # other configuration bric-a-brac...
    config.active_record.schema_format = :sql
  end
end

Next Create the database(s) just like you normally would:

rake db:create

Next Generate a migration that will create the initial table:

$ rails generate migration create_employees

Use your SQL powers to craft some DDL, perhaps the "Hello, World!" of DB applications, employees?

class CreateEmployees < ActiveRecord::Migration
  def up
    execute <<-SQL
      CREATE TABLE employees (
        id         SERIAL,
        name       VARCHAR(255) NOT NULL,
        email      VARCHAR(255) NOT NULL UNIQUE,
        start_date DATE NOT NULL,

        PRIMARY KEY (id),
        CONSTRAINT company_email CHECK (email LIKE '%@example.com')
      );
    SQL
  end

  def down
    drop_table :employees
  end
end

Lastly Deploy the reactive_record generator:

$ rails generate reactive_record:install

Go look at the generated file:

class Employees < ActiveRecord::Base
  set_table_name 'employees'
  set_primary_key :id
  validate :id, :name, :email, :start_date, presence: true
  validate :email, uniqueness: true
  validate { errors.add(:email, "Expected TODO") unless email =~ /.*@example.com/ }
end

Reactive record does not currently attempt to generate any kind of reasonable error message (I'm working on it) :)

Enjoy

Credits

Firstly, thank you, contributors!

Also a special thanks to Joe Nelson, @begriffs, for contributions and inspiration; Reactive Record would not exist without his efforts. Thanks to Bendyworks for the 20% time to work on this project!

And, of course, a huge thank you to Kelly Rauwerdink for her amazing ability to make "an art" even when all I can do is sorta half-articulate what I'm talking about. Thanks!

Footer

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].