Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/postmodern/example-activerecord-lib

Example usage of ActiveRecord in a Ruby library (not a Rails app or Rails engine)
https://github.com/postmodern/example-activerecord-lib

Last synced: 23 days ago
JSON representation

Example usage of ActiveRecord in a Ruby library (not a Rails app or Rails engine)

Awesome Lists containing this project

README

        

# example-activerecord-lib

This is an example of how to use ActiveRecord in a Ruby library, _not_ a Rails
app or Rails engine.

## Usage

```shell
$ bundle install
...
$ irb -r bundler/setup -Ilib -r library
>> Library.connect
[Library::Author(id: integer, name: string),
Library::Book(id: integer, title: string),
Library::BookAuthor(id: integer, author_id: integer, book_id: integer)]
>> author = Library::Author.create(name: 'Neal Stephenson')
=> #
>> author.books.create(title: 'Snowcrash')
=> #
>> exit
$ sqlite3 database.sqlite3
sqlite> .tables
ar_internal_metadata library_books
library_authors library_schema_migrations
library_book_authors
sqlite> SELECT * FROM library_schema_migrations;
1
2
3
sqlite> SELECT * FROM library_authors;
1|Neil Stephenson
sqlite> SELECT * FROM library_books;
1|Snowcrash
```