{"id":17041915,"url":"https://github.com/cloudhead/resourcer","last_synced_at":"2025-04-12T14:40:41.437Z","repository":{"id":893180,"uuid":"644931","full_name":"cloudhead/resourcer","owner":"cloudhead","description":"a resource-oriented object-relational mapper for document databases","archived":false,"fork":false,"pushed_at":"2011-04-13T04:38:27.000Z","size":2107,"stargazers_count":58,"open_issues_count":11,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T09:11:42.886Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudhead.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":"2010-05-03T18:59:21.000Z","updated_at":"2019-08-13T14:33:19.000Z","dependencies_parsed_at":"2022-07-05T20:40:00.905Z","dependency_job_id":null,"html_url":"https://github.com/cloudhead/resourcer","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/cloudhead%2Fresourcer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudhead%2Fresourcer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudhead%2Fresourcer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudhead%2Fresourcer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudhead","download_url":"https://codeload.github.com/cloudhead/resourcer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248582373,"owners_count":21128363,"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-10-14T09:14:10.345Z","updated_at":"2025-04-12T14:40:41.417Z","avatar_url":"https://github.com/cloudhead.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"resourcer (alpha)\n=========\n\n\u003e resource-oriented object-relational mapper for document databases.\n\nintroduction\n------------\n\n\nengines\n-------\n\n### database #\n### file #\n### memory #\n\nDefining resources\n------------------\n\nHere's the simplest of resources:\n\n    var Creature = resourcer.define('creature');\n\nThe returned `Creature` object is a *resource constructor*, in other words, a *function*.\n\nNow let's add some properties to this constructor:\n\n    Creature.property('diet'); // Defaults to String\n    Creature.property('vertebrate', Boolean);\n    Creature.property('belly', Array);\n\nAnd add a method to the prototype:\n\n    Creature.prototype.feed = function (food) {\n        this.belly.push(food);\n    };\n\nNow lets instantiate a Creature, and feed it:\n\n    var wolf = new(Creature)({\n        diet:      'carnivor',\n        vertebrate: true\n    });\n    wolf.feed('squirrel');\n\nYou can also define resources this way:\n\n    var Creature = resourcer.define('creature', function () {\n        this.property('diet');\n        this.property('vertebrate', Boolean);\n        this.property('belly', Array);\n    \n        this.prototype.feed = function (food) {\n            this.belly.push(food);\n        };\n    });\n\nDefining properties with `Resource.property`\n--------------------------------------------\n\n`Resource.property(name, type='string', options={})`\n\nLets define a *legs* property, which is the number of legs the creature has:\n\n    Creature.property('legs', Number);\n\nNote that this form is equivalent:\n\n    Creature.property('legs', 'number');\n\nIf we wanted to constrain the possible values the property could take,\nwe could pass in an object as the last parameter:\n\n    Creature.property('legs', Number, {\n        required: true,\n\n        minimum: 0,\n        maximum: 8,\n\n        assert: function (val) {\n            return val % 2 === 0;\n        }\n    });\n\nNow resourcer won't let `Creature` instances be saved unless the *legs* property\nhas a value between `0` and `8`, and is *even*,\n\nThis style is also valid for defining properties:\n\n    Creature.property('legs', Number)\n            .required()\n            .minimum(0)\n            .maximum(8)\n            .assert(function (val) { return val % 2 === 0 });\n\nIf you want to access and modify an already defined property, you can do it this way:\n\n    Creature.properties['legs'].maximum(6);\n\nSaving and fetching resources\n-----------------------------\n\n    Wolf.create({ name: 'Wolverine', age: 68 }, function (err, wolf) {\n        if (err) { throw new(Error)(err) }\n\n        console.log(wolf); // { _id: 42, resource: 'wolf', name: 'Wolverine', age: 68 }\n\n        wolf.age ++;\n        wolf.save(function (err) {\n            if (! err) console.log('happy birthday ' + wolf.name + '!');\n        });\n    });\n\n    Wolf.get(42, function (e, wolf) {\n        if (e) { throw new(Error)(e) }\n\n        wolf.update({ fur: 'curly' }, function (e, wolf) {\n            console.log(wolf.fur); // \"curly\"\n        });\n    });\n\nResource constructor methods\n----------------------------\n\nThese methods are available on all user-defined resource constructors,\nas well as on the default `resourcer.Resource` constructor.\n\n### `Resource.get(id, [callback])`\n\nFetch a resource by *id*.\n\n### `Resource.update(id, properties, [callback])`\n\nUpdate a resource with properties.\n\n### `Resource.destroy(id, [callback])`\n\nDestroy a resource by *id*.\n\n### `Resource.all([callback])`\n\nFetches all resources of this type.\n\n### `Resource.save(properties, [callback])`\n### `Resource.create(properties, [callback])`\n\nResource prototype methods\n--------------------------\n\nThese are the *prototype* methods, available on resource instances\ncreated with the `new` operator.\n\n### `Resource.prototype.save([callback])`\n### `Resource.prototype.update(properties, [callback])`\n### `Resource.prototype.destroy([callback])`\n### `Resource.prototype.reload([callback])`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudhead%2Fresourcer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudhead%2Fresourcer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudhead%2Fresourcer/lists"}