Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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)
- Host: GitHub
- URL: https://github.com/postmodern/example-activerecord-lib
- Owner: postmodern
- Created: 2022-02-18T03:47:39.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-02-19T22:16:19.000Z (over 2 years ago)
- Last Synced: 2024-08-07T08:11:33.213Z (3 months ago)
- Language: Ruby
- Size: 4.88 KB
- Stars: 13
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
```