Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wormy

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wormy

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

WORMY 🐛

A lightweight Object-Relational Mapping (ORM) library for Ruby. Allows you to keep code DRY and easily perform database operations in an object-oriented manner.

Demo

  1. From the demo directory of this repo, open pry or irb in the console
  2. load 'hp_demo.rb'
  3. Use hp_demo.rb and the API section below as a reference to play around with the data

How to Use WORMY

  • Navigate to the folder in your directory where you would like your .db database file to be saved.
  • If you have an existing database.rb file you need to rewrite, run rm database.db
  • Run cat '{YOUR_SQL_FILE_NAME}' | sqlite3 'database.db' (replacing {YOUR_SQL_FILE_NAME} with your own .sql file)
  • Then, in your project, open a connection with DBConnection.open('database.db')

Libraries

  • SQLite3
  • ActiveSupport::Inflector

API

Associations between models are defined by simple class methods, like so:

class Pet < WORMY::Base
  belongs_to :owner,
    class_name: "Wizard"

  has_one_through :house, :owner, :house

  finalize!
end

Querying and updating the database is made easy with WORMY::Base's methods like:

  • ::all
  • ::count
  • ::destroy_all
  • ::find
  • ::first
  • ::last
  • ::where
  • #create
  • #save
  • #destroy

Perform custom model validations by adding a call to validates in your subclass definition:

class House < WORMY::Base
  has_many :wizards
  has_many_through :pets, :wizards, :pets
  validates :house_name

  def house_name
    ["Gryffindor", "Slytherin", "Ravenclaw", "Hufflepuff"].include?(self.name)
  end

  finalize!
end

About WORMY

WORMY opens a connection to a provided database file by instantiating a singleton of SQLite3::Database via DBConnection. DBConnection uses native SQLite3::Database methods (execute, execute2, last_insert_row_id) to allow WORMY to perform complex SQL queries using heredocs. The Searchable and Associatable modules extend WORMY::Base to provide an intuitive API.

WORMY emphasizes convention over configuration by setting sensible defaults for associations, but also allows for easy overrides if desired.

FAQs

Package last updated on 04 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc