{"id":19170305,"url":"https://github.com/sashadev-sky/model-operandi","last_synced_at":"2026-05-16T18:08:24.940Z","repository":{"id":122652951,"uuid":"145108339","full_name":"sashadev-sky/Model-Operandi","owner":"sashadev-sky","description":"A lightweight Ruby ORM","archived":false,"fork":false,"pushed_at":"2023-02-27T23:28:40.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-06T09:39:27.177Z","etag":null,"topics":["activesupport","orm","rspec","ruby","sql"],"latest_commit_sha":null,"homepage":"","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/sashadev-sky.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-17T10:40:54.000Z","updated_at":"2023-02-27T23:28:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"00ba6ab0-8040-435e-9889-adf6a085da69","html_url":"https://github.com/sashadev-sky/Model-Operandi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sashadev-sky/Model-Operandi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sashadev-sky%2FModel-Operandi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sashadev-sky%2FModel-Operandi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sashadev-sky%2FModel-Operandi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sashadev-sky%2FModel-Operandi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sashadev-sky","download_url":"https://codeload.github.com/sashadev-sky/Model-Operandi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sashadev-sky%2FModel-Operandi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33113509,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["activesupport","orm","rspec","ruby","sql"],"created_at":"2024-11-09T09:53:36.291Z","updated_at":"2026-05-16T18:08:24.908Z","avatar_url":"https://github.com/sashadev-sky.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Model Operandi\n\n- A lightweight Ruby Object-Relational Mapping (ORM)\n- Inspired by the ActiveRecord pattern\n- Uses RSpec and a test-driven approach\n\n## Overview\n\n- The `painting.rb` and `painter.rb` files map to the database in `import_db.sql` after it is parsed by SQLite3.\n- The object classes (`Painting`, `Painter`) are mapped to the data tables (`paintings`, `painters`).\n- Object instances are mapped to the rows in the tables: each row is a single entity.\n- Attributes for each object instance (instance variables) are mapped to the columns in the tables: each column houses an additional piece of data for that single entity.\n  - `paintings` have an `id`, `title`, `year` and `painter_id`\n  - `painters` have an `id`, `name` and `birth_year`\n- `db_connection.rb` holds the `DBConnection` class, which stores the database instance after it is initialized.\n\n## Terminology\n\n**SQLite3**: One implementation of SQL, meaning it's the software that actually processes our SQL commands. Synonymous to saying it's a `relational database` or `relational database management system` (`RDBMS`).\n\n- It is:\n  - Serverless: a library loaded by our program, which then directly interacts with the underlying database data.\n  - A common development database, not used for production because of performance limitations.\n\n**Mapping (v)**: The act of determining how objects and their relationships are persisted in permanent data storage.\n\n**Mapping (n)**: The definition of how an object's property or a relationship is persisted in permanent storage.\n\n**Object-Relational Mapping (ORM)** is a technique that lets the developer query and manipulate data from a relational database using an object-oriented paradigm.\n\n- An ORM is written in an object-oriented language (in this case, Ruby) and wrapped around the relational database.\n\n- Motivation: one can easily interact with the data and its attributes as objects, without writing SQL statements directly.\n\n## API\n\n- `::all`: return an array of all the records in the DB\n- `::find`: return a single record retrieved by primary key\n- `::find_by`: return the first record that matches specified attributes\n- `::where`: return an array of all records that match specified attributes\n- `#save`: `update`s or inserts a record into the DB depending on whether it already exists in the table\n- `#update`: updates the DB row corresponding to the record with the given attribute values\n\n## Testing the ORM\n\nYou can use Pry to see the ORM in action.\n\nTo set up the environment, make sure you are inside of the project directory in your terminal and run:\n\n```bash\n# install dependencies\nbundle install\n\n# start up pry\npry\n```\n\nIn the pry session:\n\n- Refer to the \"testing\" section commented out at the bottom of `painter.rb`\n\n- If at any point you feel that your database is corrupted, run `DBConnection.reset!` to reset it back to its originally seeded data.\n\n- To see the SQL queries behind the Ruby methods you test, set `PRINT_QUERIES = true` (currently set to false) at the top of the `db_connection.rb` file.\n\nRSpec:\n\n- See the `spec` folder for documentation on the functionality of this ORM's interface.\n\n- To run the specs, in your terminal run:\n\n```bash\n# test all files at once\nbundle exec rspec\n\n# test individual spec files\nbundle exec rspec ./spec/file_name.rb\n```\n\n---------------------------------------------------------\n\n### SQL Concepts (personal use)\n\n- `Data Definition Language` (`DDL`): defines the structure of our database (also called schema). 3 operators that SQL provides:\n  - `CREATE table`\n  - `ALTER table`\n  - `DROP table`\n- `Data Manipulation Language` (`DML`): add/edit/delete the data in the database. 4 main DML operations that SQL provides:\n  - `SELECT`: retrieve values from one or more rows\n  - `INSERT`: insert a row into a table\n  - `UPDATE`: update values in one or more existing rows\n  - `DELETE`: delete one or more rows\n- Avoiding the `Bobby Table` (colloquially called `SQL injection`) attack\n  - Important to sanitize `WHERE` clause values and other parts of dynamic SQL data that come from user input\n- `Singleton` module / pattern\n- Heredocs\n- `ActiveSupport::Inflector`\n- `RSpec`\n  - Model specs are considered **unit tests** since they test each model as an independent unit\n  - These will be the most specific, detailed tests in a Rails app but also one of the most essential\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsashadev-sky%2Fmodel-operandi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsashadev-sky%2Fmodel-operandi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsashadev-sky%2Fmodel-operandi/lists"}