{"id":20669307,"url":"https://github.com/ivanparvaresh/sarina-activerecord","last_synced_at":"2025-08-05T12:05:01.018Z","repository":{"id":96184927,"uuid":"75232367","full_name":"ivanparvaresh/Sarina-ActiveRecord","owner":"ivanparvaresh","description":"Sarina data layer ","archived":false,"fork":false,"pushed_at":"2016-12-01T13:39:28.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-08T08:46:41.863Z","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/ivanparvaresh.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":"2016-11-30T22:21:04.000Z","updated_at":"2016-12-01T13:29:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"e57ab192-38ee-4006-bce1-41702e4260ce","html_url":"https://github.com/ivanparvaresh/Sarina-ActiveRecord","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ivanparvaresh/Sarina-ActiveRecord","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanparvaresh%2FSarina-ActiveRecord","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanparvaresh%2FSarina-ActiveRecord/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanparvaresh%2FSarina-ActiveRecord/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanparvaresh%2FSarina-ActiveRecord/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ivanparvaresh","download_url":"https://codeload.github.com/ivanparvaresh/Sarina-ActiveRecord/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanparvaresh%2FSarina-ActiveRecord/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268893472,"owners_count":24324663,"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","status":"online","status_checked_at":"2025-08-05T02:00:12.334Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-16T20:13:45.265Z","updated_at":"2025-08-05T12:05:00.953Z","avatar_url":"https://github.com/ivanparvaresh.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sarina.ActiveRecord\n\nThis plugin has implmeented ActiveRecord design pattern for sarina. \nPlugin created by [JavadParvaresh](https://github.com/javadparvaresh).\n\n\u003e In software engineering, the active record pattern is an architectural pattern found in software that stores in-memory object data in relational databases. It was named by Martin Fowler in his 2003 book Patterns of Enterprise Application Architecture.[1] The interface of an object conforming to this pattern would include functions such as Insert, Update, and Delete, plus properties that correspond more or less directly to the columns in the underlying database table.([wikipedia](https://en.wikipedia.org/wiki/Active_record_pattern))\n\nPlugin has build on top of [Knex](https://github.com/tgriesser/knex) and [bookshelf](https://github.com/tgriesser/bookshelf).\n\n## Table of contents\n- [Quick Start](#quick-start)\n- [Bugs and feature requests](#bugs-and-feature-requests)\n- [The Basics](#the-basics)\n- [The Configuration](#the-configuration)\n- [Apis](#apis)\n\n## Quick start\n\nSeveral quick start options are available:\n- Clone the repo: `git clone https://github.com/javadparvaresh/Sarina-ActiveRecord.git`\n- Install with [npm](https://www.npmjs.com): `npm install sarinaactiverecord`\n\n## Bugs and feature requests\n\nHave a bug or a feature request? [please open a new issue](https://github.com/javadparvaresh/Sarina-ActiveRecord/issues/new).\n\n## The Basics\n```javascript\n\nvar sarina=require(\"sarina\");\nvar sarinaactiverecord=require(\"sarinaactiverecord\");\n\n// create a sarina app by passing configuration\nvar app=sarina.create({\n    db:{\n        \"default\":{\n            \"client\":\"mysql\",\n            \"host\":\"127.0.0.1\",\n            \"database\":\"SampleDb\",\n            \"user\":\"root\",\n            \"password\":\"\"\n        }\n    }\n});\n\n// add to modules\napp.module(sarinaactiverecord);\n\n// Defining model\napp.factory(\"Sample\",[\"sarina.activerecord.provider\"],function(ar){\n    return ar.define()\n        .config(\"default\")\n        .table(\"TbSample\")\n        .column(\"id\",\"INT\",11,[\"unique\"])\n        .column(\"TITLE\",\"VARCHAR\",50)\n        .create();\n});\n\n\n// using model\napp.service(\"sample.dataprovider\",[\"Sample\"],function(model){\n\n    return {\n        insert:function(title){\n            return new Promise(function(resolve,reject){\n                new model({\n                    \"title\":title\n                    })\n                    .insert()\n                    .then(resolve)\n                    .catch(reject);\n            });\n        },\n        update:function(id,title){\n            return new Promise(function(resolve,reject){\n                new model()\n                    .where(\"id\",id)\n                    .update({\n                        \"title\":title\n                    })\n                    .then(resolve)\n                    .catch(reject);\n            });\n        },\n        remove:function(id){\n            return new Promise(function(resolve,reject){\n                new model()\n                    .where(\"id\",id)\n                    .remove()\n                    .then(resolve)\n                    .catch(reject);\n            })\n        },\n        fetchAll:function(){\n            return new Promise(function(resolve,reject){\n                return new model()\n                    .fetchAll()\n                    .then(resolve)\n                    .catch(reject);\n            })\n            \n        }\n    }\n    \n\n});\n\n\n// add a executable process to sarina\napp.exec(\"runner\",[\"sample.dataprovider\"],function(sampledp){\n    return {\n        run:function(){\n            return new Promise(function(resolve,reject){\n                sampledp.fetchAll()\n                    .then(function(result){\n                        console.log(\"Result:\",result);\n                    }).catch(reject);\n            })\n        }\n    }\n});\n\n// finally we need to start app\napp.start();\n\n```\n\n## The Configuration\n```javascript\n\nvar sarina=require(\"sarina\");\nvar sarinaactiverecord=require(\"sarinaactiverecord\");\n\nvar app=sarina.create({});\n\napp.config(\"sarina.customConfig\",[\"sarina.activerecord.provider\"],function(provider){\n\n    provider.set(\"myConfig\",{\n        \"client\":\"mysql\",\n        \"host\":\"127.0.0.1\",\n        \"database\":\"database\",\n        \"user\":\"root\",\n        \"password\":\"\"\n    });\n\n    app.factory(\"simpleModel\",[\"sarina.activerecord\"],function(ar){\n        return \n            ar.define()\n            .config(\"myConfig\") // using my custom config\n            .table(\"tbSimple\")\n            .column(\"id\",\"INT\",33,[\"unique\"])\n            .column(\"title\",\"VARCHAR\",200)\n            .create();\n    });\n\n});\n\n\n```\n\n\n\n## Apis\n\n1. Query \n```javascript\n\n    //....\n\n    new Model()\n        .where(\"column1\",\"equalto\") \n        .where(\"column2\",\"test\") // an other where clause\n        .whereRaw(\"columnd3 \u003e= :column3\",value)\n        .orderBy(\"column4\") // order by ascending\n        .orderByDesc(\"column4\") // order by descending\n        .limit(1) // limiting fetched rows\n        .skip(2) // skip rows \n\n        .count() // return count of Query\n        .fetchOne() // return first matched record\n        .fetchAll() // return all matched records\n\n        .query() // raw created query as string\n    //....\n\n```\n\n2. Manipulating Data\n```javascript\n\n    // ...\n\n    // Insert or Update\n    new Model({\n        Column1 : \"New Value\"\n    }).where(\"id\",1)\n    .save();\n\n    // Insert\n    new Model({\n        Column1 : \"New Value\"\n    })\n    .insert();\n\n    // Update\n    new Model({\n        Column1 : \"New Value\"\n    }).where(\"id\",1)\n    .update();\n\n    // Remove\n    new Model()\n        .where(\"id\",1)\n        .remove();\n\n    // ...\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanparvaresh%2Fsarina-activerecord","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivanparvaresh%2Fsarina-activerecord","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanparvaresh%2Fsarina-activerecord/lists"}