{"id":21480485,"url":"https://github.com/paperhive/octonom","last_synced_at":"2025-07-15T12:32:09.460Z","repository":{"id":57313376,"uuid":"95747654","full_name":"paperhive/octonom","owner":"paperhive","description":"General-purpose models and collections with multi-database support, written in TypeScript","archived":false,"fork":false,"pushed_at":"2018-06-06T08:45:35.000Z","size":368,"stargazers_count":12,"open_issues_count":14,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-05-01T03:43:07.936Z","etag":null,"topics":["collection","collections","couchdb","database","document-database","model","models","mongodb","multi-database-support","nodejs","object-document-mapper","object-relational-mapper","odm","orm","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/paperhive.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}},"created_at":"2017-06-29T06:50:56.000Z","updated_at":"2023-12-19T17:40:36.000Z","dependencies_parsed_at":"2022-09-20T23:10:40.760Z","dependency_job_id":null,"html_url":"https://github.com/paperhive/octonom","commit_stats":null,"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paperhive%2Foctonom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paperhive%2Foctonom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paperhive%2Foctonom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paperhive%2Foctonom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paperhive","download_url":"https://codeload.github.com/paperhive/octonom/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226038783,"owners_count":17564046,"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":["collection","collections","couchdb","database","document-database","model","models","mongodb","multi-database-support","nodejs","object-document-mapper","object-relational-mapper","odm","orm","typescript"],"created_at":"2024-11-23T12:15:26.764Z","updated_at":"2024-11-23T12:15:29.539Z","avatar_url":"https://github.com/paperhive.png","language":"TypeScript","readme":"# octonom\n\n[![npm version](https://badge.fury.io/js/octonom.svg)](https://badge.fury.io/js/octonom)\n[![Greenkeeper badge](https://badges.greenkeeper.io/paperhive/octonom.svg)](https://greenkeeper.io/)\n[![Build Status](https://travis-ci.org/paperhive/octonom.svg?branch=master)](https://travis-ci.org/paperhive/octonom)\n[![codecov](https://codecov.io/gh/paperhive/octonom/branch/master/graph/badge.svg)](https://codecov.io/gh/paperhive/octonom)\n\n\u003cimg src=\"https://paperhive.github.io/octonom/octonom.svg\" width=\"400\"\u003e\u003c/img\u003e\u003cbr\u003e\n###### Logo by [Laura Simonite](https://twitter.com/LFSimonite) (CC-BY 4.0)\n\nOctonom brings you TypeScript-based models and collections for any database with proper separation of concerns:\n\n* **Models**\n  * have a schema\n  * instances can be validated\n  * are independent of how the data is actually stored in a database\n* **Collections**\n  * deal with getting your data from/to the database\n  * raw database objects are mapped to rich typescript models on the fly (and vice versa)\n  * are specific to the database you use (e.g. `MongoCollection`, `CouchCollection`)\n\n## Features of octonom\n\n* clear separation of concerns:\n  * models allow you to work with your data\n  * collections take care of persisting and retrieving data to/from a database\n* models are TypeScript/ES6 classes with typed properties\n* extensible: if you need something specific, just extend the octonom classes\n* multi-database support: implementing a collection for your favorite database is just a few LOCs\n* runs in NodeJS and browsers\n\n## Examples\n\n### Model\n\nLet's define a model:\n\n```typescript\nimport { Model, Property } from 'octonom';\n\nexport class Person extends Model {\n  @Property.String()\n  public id: string;\n\n  @Property.String()\n  public name: string;\n\n  @Property.Number({integer: true, min: 0})\n  public age: number;\n\n  public makeOlder() {\n    this.age++;\n  }\n}\n```\n\nLet's create an instance:\n\n```typescript\n// create an instance with initial data\nconst person = new Person({name: 'Marx', age: 200});\n\n// call a model instance method\nperson.makeOlder();\nconsole.log(person); // {id: '42', name: 'Marx', age: 201}\n\n// set a model instance property\nperson.name = 'Rosa';\nconsole.log(person); // {id: '42', name: 'Rosa', age: 201}\n```\n\n### Collection\n\nHaving a local instance of a model is really nice but you probably want to persist it to some database. Collections provide a bridge between raw data objects in a database and the class-based models.\n\nLet's create a collection for people and connect it with a database:\n\n```typescript\nimport { MongoClient } from 'mongodb';\nimport { MongoCollection } from 'octonom';\n\n// create people collection\nconst people = new MongoCollection('people', Person, {modelIdField: 'id'});\n\n// connect with to database\nconst db = await MongoClient.connect('mongodb://localhost:27017/mydb');\n\n// init collection in database\nawait people.init(db);\n```\n\nInserting and retrieving models is straight-forward:\n\n```typescript\n// insert a person\nconst karl = new Person({id: 'C4p1T4l', name: 'Marx', age: 200});\nawait people.insertOne(karl);\n\n// retrieve a person\nconst foundPerson = await people.findById('C4p1T4l');\n\n// foundPerson is again a model instance so we can call its methods\nfoundPerson.makeOlder();\nconsole.log(foundPerson); // {id: 'C4p1T4l', name: 'Marx', age: 201}\n\n// update a person\nawait people.update(foundPerson);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaperhive%2Foctonom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaperhive%2Foctonom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaperhive%2Foctonom/lists"}