{"id":13878603,"url":"https://github.com/postmodern/example-activerecord-lib","last_synced_at":"2025-08-08T16:04:08.308Z","repository":{"id":66004910,"uuid":"460700405","full_name":"postmodern/example-activerecord-lib","owner":"postmodern","description":"Example usage of ActiveRecord in a Ruby library (not a Rails app or Rails engine)","archived":false,"fork":false,"pushed_at":"2025-05-27T03:27:37.000Z","size":9,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-27T04:28:53.655Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/postmodern.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-02-18T03:47:39.000Z","updated_at":"2025-05-27T03:27:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"57057857-d287-4c8e-a46d-aed1d5ad2fa1","html_url":"https://github.com/postmodern/example-activerecord-lib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/postmodern/example-activerecord-lib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postmodern%2Fexample-activerecord-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postmodern%2Fexample-activerecord-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postmodern%2Fexample-activerecord-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postmodern%2Fexample-activerecord-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/postmodern","download_url":"https://codeload.github.com/postmodern/example-activerecord-lib/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postmodern%2Fexample-activerecord-lib/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269447940,"owners_count":24418762,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-06T08:01:54.456Z","updated_at":"2025-08-08T16:04:08.299Z","avatar_url":"https://github.com/postmodern.png","language":"Ruby","readme":"# example-activerecord-lib\n\nThis is an example of how to use ActiveRecord in a Ruby library, _not_ a Rails\napp or Rails engine.\n\n## Usage\n\n```shell\n$ bundle install\n$ irb -r bundler/setup -Ilib -r library\n```\n```ruby\nLibrary.connect\n# == 1 CreateAuthorsTable: migrating ============================================\n# -- create_table(:library_authors)\n#    -\u003e 0.0012s\n# == 1 CreateAuthorsTable: migrated (0.0014s) ===================================\n# \n# == 2 CreateBooksTable: migrating ==============================================\n# -- create_table(:library_books)\n#    -\u003e 0.0011s\n# == 2 CreateBooksTable: migrated (0.0012s) =====================================\n# \n# == 3 CreateBookAuthorsTable: migrating ========================================\n# -- create_table(:library_book_authors)\n#    -\u003e 0.0021s\n# == 3 CreateBookAuthorsTable: migrated (0.0023s) ===============================\n# \n# =\u003e \n# [Library::Author(id: integer, name: string),\n#  Library::Book(id: integer, title: string),\n#  Library::BookAuthor(id: integer, author_id: integer, book_id: integer)]\n\nauthor1 = Library::Author.create(name: 'Sam Ruby')\n# =\u003e #\u003cLibrary::Author:0x00007f9861f9bfe0 id: 1, name: \"Sam Ruby\"\u003e\nauthor2 = Library::Author.create(name: 'Dave Thomas')\n# =\u003e #\u003cLibrary::Author:0x00007f9861f10a08 id: 2, name: \"Dave Thomas\"\u003e\n\nbook = Library::Book.create(title: 'Agile Web Development with Rails 7', authors: [author1, author2])\n# =\u003e #\u003cLibrary::Book:0x00007f4c5884b650\n#     id: nil,\n#     title: \"Agile Web Development with Rails 7\"\u003e\n```\n\n```shell\n$ sqlite3 database.sqlite3\n```\n```sql\nsqlite\u003e .tables\nar_internal_metadata  library_book_authors  schema_migrations   \nlibrary_authors       library_books       \n\nsqlite\u003e SELECT * FROM schema_migrations;\n1\n2\n3\n\nsqlite\u003e .schema library_authors\nCREATE TABLE IF NOT EXISTS \"library_authors\" (\"id\" integer PRIMARY KEY AUTOINCREMENT NOT NULL, \"name\" varchar NOT NULL);\nCREATE UNIQUE INDEX \"index_library_authors_on_name\" ON \"library_authors\" (\"name\");\n\nsqlite\u003e SELECT * FROM library_authors;\n1|Sam Ruby\n3|Dave Thomas\n\nsqlite\u003e .schema library_books\nCREATE TABLE IF NOT EXISTS \"library_books\" (\"id\" integer PRIMARY KEY AUTOINCREMENT NOT NULL, \"title\" varchar);\nCREATE UNIQUE INDEX \"index_library_books_on_title\" ON \"library_books\" (\"title\");\n\nsqlite\u003e SELECT * FROM library_books;\n1|Agile Web Development with Rails 7\n\nsqlite\u003e .schema library_book_authors \nCREATE TABLE IF NOT EXISTS \"library_book_authors\" (\"id\" integer PRIMARY KEY AUTOINCREMENT NOT NULL, \"author_id\" integer NOT NULL, \"book_id\" integer NOT NULL, CONSTRAINT \"fk_rails_29993e851a\"\nFOREIGN KEY (\"author_id\")\n  REFERENCES \"library_authors\" (\"id\")\n, CONSTRAINT \"fk_rails_7a760ae47a\"\nFOREIGN KEY (\"book_id\")\n  REFERENCES \"library_books\" (\"id\")\n);\nCREATE INDEX \"index_library_book_authors_on_author_id\" ON \"library_book_authors\" (\"author_id\");\nCREATE INDEX \"index_library_book_authors_on_book_id\" ON \"library_book_authors\" (\"book_id\");\nCREATE UNIQUE INDEX \"index_library_book_authors_on_author_id_and_book_id\" ON \"library_book_authors\" (\"author_id\", \"book_id\");\n\nsqlite\u003e SELECT * FROM library_book_authors;\n1|1|1\n2|2|1\n```\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostmodern%2Fexample-activerecord-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpostmodern%2Fexample-activerecord-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostmodern%2Fexample-activerecord-lib/lists"}