{"id":22793082,"url":"https://github.com/kripod/knex-orm","last_synced_at":"2025-04-16T18:48:57.555Z","repository":{"id":81144154,"uuid":"54731400","full_name":"kripod/knex-orm","owner":"kripod","description":"Knex-based object-relational mapping for JavaScript.","archived":false,"fork":false,"pushed_at":"2018-01-26T01:37:52.000Z","size":699,"stargazers_count":61,"open_issues_count":11,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T02:51:27.968Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/kripod.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-03-25T16:30:45.000Z","updated_at":"2023-09-22T19:03:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"f897831c-d13a-4f4a-8ebb-cac934366326","html_url":"https://github.com/kripod/knex-orm","commit_stats":{"total_commits":97,"total_committers":1,"mean_commits":97.0,"dds":0.0,"last_synced_commit":"d6f5e9fbc63772d0e4b9be08c832564eac6218c7"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kripod%2Fknex-orm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kripod%2Fknex-orm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kripod%2Fknex-orm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kripod%2Fknex-orm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kripod","download_url":"https://codeload.github.com/kripod/knex-orm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249266477,"owners_count":21240762,"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-12-12T03:17:56.866Z","updated_at":"2025-04-16T18:48:57.549Z","avatar_url":"https://github.com/kripod.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [knex-orm](http://kripod.github.io/knex-orm)\n\nKnex-based object-relational mapping for JavaScript.\n\n[![Version (npm)](https://img.shields.io/npm/v/knex-orm.svg)](https://npmjs.com/package/knex-orm)\n[![Build Status](https://img.shields.io/travis/kripod/knex-orm/master.svg)](https://travis-ci.org/kripod/knex-orm)\n[![Code Coverage](https://img.shields.io/codecov/c/github/kripod/knex-orm/master.svg)](https://codecov.io/gh/kripod/knex-orm)\n[![Gitter](https://img.shields.io/gitter/room/kripod/knex-orm.svg)](https://gitter.im/kripod/knex-orm)\n\n## Introduction\n\nThe motivation behind this project is to combine the simplicity of [Bookshelf][]\nwith the power of [Knex][] and modern ECMAScript features.\n\nKnex-ORM aims to provide a wrapper for every significant method of [Knex][],\nwhile keeping the ORM code overhead as low as possible.\n\n[bookshelf]: http://bookshelfjs.org\n\n[knex]: http://knexjs.org\n\n## Getting started\n\nInstalling [Knex][] and at least one of its supported database drivers as peer\ndependencies is mandatory.\n\n```bash\n$ npm install knex --save\n$ npm install knex-orm --save\n\n# Then add at least one of the following:\n$ npm install pg --save\n$ npm install mysql --save\n$ npm install mariasql --save\n$ npm install sqlite3 --save\n```\n\nAn instance of the Knex-ORM library can be created by passing a [Knex][] client\ninstance to the entry class.\n\n```js\nconst knex = require('knex');\nconst KnexOrm = require('knex-orm');\n\nconst Database = new KnexOrm(\n  knex({\n    client: 'sqlite3',\n    connection: {\n      filename: './dev.sqlite3',\n    },\n  })\n);\n\nclass Employee extends Database.Model {\n  static get tableName() { return 'employees'; } // Redundant\n\n  // Specify related Models which can optionally be fetched\n  static get related() {\n    return {\n      company: this.belongsTo('Company'), // No Model cross-referencing\n    };\n  }\n}\n\nclass Company extends Database.Model {\n  // The 'tableName' property is omitted on purpose, as it gets assigned\n  // automatically based on the Model's class name.\n\n  static get primaryKey() { return 'rank'; }\n\n  static get related() {\n    return {\n      employees: this.hasMany('Employee'),\n    };\n  }\n}\n\n// Register Models to make them relatable without cross-referencing each other\nDatabase.register(Employee);\nDatabase.register(Company);\n```\n\n## Examples\n\nCreating and storing a new Model:\n\n```js\nconst famousCompany = new Company({\n  name: 'A Really Famous Company',\n  email: 'info@famouscompany.example'\n});\n\nfamousCompany.save()\n  .then((ids) =\u003e {\n    // An ordinary response of a Knex 'insert' query\n    // (See http://knexjs.org/#Builder-insert)\n    console.log(ids);\n  });\n```\n\nModifying an existing Model gathered by a query:\n\n```js\nCompany.query().where({ email: 'info@famouscompany.example' }).first()\n  .then((company) =\u003e {\n    // Response of a Knex 'where' query, with results parsed as Models\n    // (See http://knexjs.org/#Builder-where)\n    console.log(company); // Should be equal with 'famousCompany' (see above)\n\n    company.name = 'The Most Famous Company Ever';\n    return company.save();\n  })\n  .then((rowsCount) =\u003e {\n    // An ordinary response of a Knex 'update' query\n    // (See http://knexjs.org/#Builder-update)\n    console.log(rowsCount); // Should be 1\n  });\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkripod%2Fknex-orm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkripod%2Fknex-orm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkripod%2Fknex-orm/lists"}