{"id":19485647,"url":"https://github.com/pyozer/morm.js","last_synced_at":"2025-11-07T18:04:36.087Z","repository":{"id":66215387,"uuid":"173897550","full_name":"Pyozer/mORM.js","owner":"Pyozer","description":"School project to learn how to dev an ORM for PostegreSQL","archived":false,"fork":false,"pushed_at":"2019-03-12T20:11:31.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-08T07:48:35.374Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Pyozer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2019-03-05T07:33:28.000Z","updated_at":"2019-03-12T20:11:33.000Z","dependencies_parsed_at":"2023-02-24T09:00:32.750Z","dependency_job_id":null,"html_url":"https://github.com/Pyozer/mORM.js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pyozer%2FmORM.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pyozer%2FmORM.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pyozer%2FmORM.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pyozer%2FmORM.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Pyozer","download_url":"https://codeload.github.com/Pyozer/mORM.js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240722236,"owners_count":19847070,"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","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-11-10T20:29:13.859Z","updated_at":"2025-11-07T18:04:36.015Z","avatar_url":"https://github.com/Pyozer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mORM.js\n\nSchool project to learn how to dev an ORM for PostegreSQL (can be extend with other databases like MySQL, MongoDB)\n\n## How to use it\n\n### Initialize the database connection\n\nYou can define your own models in `entities`'s folder (like predefined Student, Project or Note).\n\nWhen you have created your models, you must initialize the database connection :\n\n```javascript\nlet orm = new mOrm()\n\nawait orm.createConnection({\n    // Instead of uri, you can provide in separate parameters: database, host, ...\n    uri: 'postgresql://podpak:@localhost:5432/podpak',\n    synchronize: true, // DROP all tables at started\n}, {\n    // Your model list\n    entities: [\n        Student,\n        Project,\n        Note\n    ],\n})\n```\n\n### Manipulate data\n\nAfter the database initialization, you have different methods that you can use with the models :\n\n- save(data)\n- count()\n- findByPk(id, { attributes = [] } = {})\n- findAll({ where = {}, attributes = [] } = {})\n- findOne({ where = {}, attributes = [] } = {})\n- update(data)\n- remove(data)\n\nTo use theses methodes you have to do :\n\n```javascript\nconst studentEntity = orm.getEntity('Student')\nconsole.log(await studentEntity.count())\n```\n\n### Relations\n\nmOrm.js support simple relations, you can have :\n\n- Many-to-one\n- One-To-Many\n- Many-To-Many\n\nTo add a relation, you can do :\n\n```javascript\n// Get models instances\nconst studentEntity = orm.getEntity('Student')\nconst projectEntity = orm.getEntity('Project')\nconst noteEntity = orm.getEntity('Note')\n\n// Add in Project table a student foreignKey\nawait projectEntity.hasOne(Student)\n// Add join table, with note and project foreignKey\nawait projectEntity.manyToMany(Note)\n// Add student foreignKey in Note\nawait studentEntity.hasMany(Note)\n```\n\nAfter doing this, you can have access to new methods.\n\nWith the previous example, you have access to :\n\n```javascript\n// Get project with student data, of student with id #1\nconst { firstname, name } = await projectEntity.getStudent({\n    where: { studentid: 1 }\n})\nconsole.log(`Project's student: ${firstname + \": \" + name}`);\n```\n\n```javascript\n// Get all notes of student with id #1\nconst studentNotes = await studentEntity.getNotes({\n    where: { studentid: 1 }\n})\nconsole.log(`\n    Notes: ${studentNotes.map(e =\u003e e.firstname + \": \" + e.note).join(', ')}\n`);\n```\n\nYou can see that a method `getStudent` has been added for relation `hasOne` and a method `getNotes` has been added for relation `hasMany`.\nObviously, the methods name depend on Table name defined in models.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyozer%2Fmorm.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpyozer%2Fmorm.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyozer%2Fmorm.js/lists"}