{"id":19986412,"url":"https://github.com/sourcec0de/es6-model-layer","last_synced_at":"2026-05-14T19:06:39.978Z","repository":{"id":147151712,"uuid":"60673565","full_name":"sourcec0de/es6-model-layer","owner":"sourcec0de","description":"(ALPHA) An example on creating an es6 model layer","archived":false,"fork":false,"pushed_at":"2016-06-08T06:38:43.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-12T11:32:58.693Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sourcec0de.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":"2016-06-08T06:18:35.000Z","updated_at":"2016-06-08T06:33:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"9bfffba2-ccc8-4570-a9e2-7fb7ee364b82","html_url":"https://github.com/sourcec0de/es6-model-layer","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/sourcec0de%2Fes6-model-layer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcec0de%2Fes6-model-layer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcec0de%2Fes6-model-layer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcec0de%2Fes6-model-layer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sourcec0de","download_url":"https://codeload.github.com/sourcec0de/es6-model-layer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241420122,"owners_count":19960033,"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-13T04:29:05.392Z","updated_at":"2026-05-14T19:06:34.957Z","avatar_url":"https://github.com/sourcec0de.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"es6-model-layer\n===\n\nNote this is an **ALPHA** example. It's only been lightly tested.\nThis is purely for conceptual use.\n\n- `index.js` is where the database connection itself is setup\n- `lib/` contains the base classes and utils\n- `models` is where i've chosen to house example model files\n\nIn this scenario there are two tables `users` and `identities`.\nThis is an oauth pattern for allowing people to link their auth providers.\n\nI am using this as a way of demonstraighting management of relationships without\nan ORM that uses methods like `hasMany` or `belongsTo`. While these conventions\nmake sense it is easier to reason about and debug code you've written yourself\nRather than relying on implicit attributes and methods that are reflected by the library itself.\n\nIt is also prudent to note that because this library would rely on a a SQL database\nthere is not really much reason to manage basic schema. It uses other libraries for\nperforming advanced schema validation like ensuring the format of a UUID. Where as\nsetting default values and updating `updateAt` timestamps can be left to the database\nsystem itself. This is not an abstration for programatically managing the database.\nKnex (the underlying query builder) has a great interface for performing schema upgrades and migrations etc.\n\nIn the `model/users.js` file I've created an extended class that uses the `identities` model\nto perform a relational query.\n\nThe example is executed something like this.\n\n```js\nlet Users = require('./models/users');\n\nUsers.findOne({id: 1}).then((user)=\u003e{\n  return user.getIdentities();\n}).then((identities)=\u003e{\n  // the final result is all the identities belonging to the user with id 1`\n})\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourcec0de%2Fes6-model-layer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsourcec0de%2Fes6-model-layer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourcec0de%2Fes6-model-layer/lists"}