{"id":23665859,"url":"https://github.com/alfonsog-dev/orm-eje","last_synced_at":"2025-09-01T18:32:13.683Z","repository":{"id":189437584,"uuid":"680680034","full_name":"AlfonsoG-dev/orm-eje","owner":"AlfonsoG-dev","description":"A Simple ORm in javaScript","archived":false,"fork":false,"pushed_at":"2024-12-18T22:34:18.000Z","size":100,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-18T23:20:16.143Z","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/AlfonsoG-dev.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":"2023-08-20T03:32:49.000Z","updated_at":"2024-12-18T22:34:21.000Z","dependencies_parsed_at":"2023-10-11T07:59:30.899Z","dependency_job_id":"748a35b6-df24-4927-97fc-c44427e27c40","html_url":"https://github.com/AlfonsoG-dev/orm-eje","commit_stats":null,"previous_names":["alfonsog-dev/orm-eje"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlfonsoG-dev%2Form-eje","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlfonsoG-dev%2Form-eje/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlfonsoG-dev%2Form-eje/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlfonsoG-dev%2Form-eje/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlfonsoG-dev","download_url":"https://codeload.github.com/AlfonsoG-dev/orm-eje/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231705124,"owners_count":18413963,"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-29T06:18:23.469Z","updated_at":"2024-12-29T06:18:27.067Z","avatar_url":"https://github.com/AlfonsoG-dev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# My ORM\n- ORM like app in javascript\n- i try to recreate an orm functionality in javascript\n\n# External dependencies\n\u003e- [mysql server 8.0.34](https://dev.mysql.com/downloads/mysql/)\n\u003e- [nodeJS 20.9.0](https://nodejs.org/es)\n\n# Other dependencies \n\u003e- mysql2\n\u003e- npm\n\n# Features\n- [x] count operation\n- [x] select using: patterns, where clause, in clause\n- [x] CRUD operations\n- [x] inner join operation\n- [x] migration operations \n\n# TODO\n\n- [ ] Support of prepared statements.\n\n\n# Instructions\n\n\u003e- `git clone https://github.com/AlfonsoG-dev/orm-eje.git`\n\u003e- `cd ./orm-eje`\n\u003e- `npm install`\n\u003e- `npm start`\n\n# Usage\n\n\u003e- create in the `utils` directory a file name: *DbConfig* with the following class\n```js\nexport default class DbConfig {\n    constructor(db_name=\"\") {\n        this.db_name = db_name\n    }\n    normal_config() {\n        return  {\n            host: \"\",\n            user: \"\",\n            password: \"\",\n            database: this.db_name\n        }\n    }\n    pool_config() {\n        return {\n            connectionLimit: 2,\n            host: 'my_ip_host',\n            user: 'database_user',\n            password: 'user_password',\n            database: this.db_name\n        }\n    }\n\n}\n```\n\n\u003e- create the model for the database:\n\u003e- create a folder -\u003e `md ./src/model`\n\u003e- create a file with the name: \"DbModel.js\"\n\u003e- initialize the database state for model usage\n```js\nexport default class User {\n    user_id_pk\n    nombre\n    email\n    constructor() {\n\n    }\n    initDB() {\n        this.user_id_pk = 'int not null unique primary kay auto_increment'\n        this.nombre = 'varchar(100) not null'\n        this.email = 'varchar(100) not null unique'\n    }\n}\n```\n\n## Operations\n\n```js\n//dependencias\nimport Operaciones from './services/Operations'\nimport User from \"./model/DbModel.js\"\nimport DbConfig from \"./utils/DbConfig.js\"\nimport DbConection from \"./services/DbConection\"\n\n\n// model instance\nconst model = new User()\nconst config = new DbConfig(\"database name\")\nmodel.initDB()\n\n// instance of database connection\nconst cursor = new DbConection(config).normal_conection()\n\n// database and table operations\nconst op = new Operaciones('consulta', 'users', cursor, model)\n\n//contar \nop.count_column(['nombre', 'rol'])\n.then((res) =\u003e console.log(res))\n.catch((err) =\u003e {throw err})\n\n\n//leer nombre y email de 2 registros\nop.read({options: 'nombre, email', limit:2})\n.then((res) =\u003e console.log(res))\n.catch((err) =\u003e {throw err})\n\n//buscar por id\nop.find({\n    options: [\"nombre\", \"email\"],\n    where: {\n        id: 1\n    }\n})\n.then((res) =\u003e console.log(res))\n.catch((err) =\u003e {throw err})\n\n//buscar entre varios valores\nop.findIn(\"nombre\", ['alfonso', 'test', 'admin'])\n.then((res) =\u003e console.log(res))\n.catch((err) =\u003e {throw err})\n\n//buscar por patron para varias columnas\nop.findPattern(\"admin\", ['nombre', 'rol'])\n.then((res) =\u003e console.log(res))\n.catch((err) =\u003e {throw err})\n\n// busca valor max and min\nconst condition = {\n    nombre: \"alfonso\"\n}\nconst options = {\n    min: [\"password\"],\n    max: [\"create_at\"]\n}\nop.find_min_max(condition, options, \"and\")\n.then((res) =\u003e console.log(res))\n.catch((err) =\u003e { throw err })\n\n//modelo del usuario \nconst u = {\n    nombre: 'test',\n    email: 'test@test1',\n    password: 'test',\n    rol: 'test'\n}\n// registrar usuario\nop.save(u)\n.then((res) =\u003e console.log(res))\n.catch((err) =\u003e {throw err})\n\nconst modificar = {\n    nombre: 'test',//para la condición no para actualizar\n    email: 'test@admin',//para actualizar desde aqui\n    password: 'test123',\n    rol: 'test1'\n}\n\n//actualizar por nombre\nop.update(modificar)\nthen((res) =\u003e console.log(res))\n.catch((err) =\u003e {throw err})\n\n//eliminar por id\nop.remove({\n    id: 2\n}).then((res) =\u003e console.log(res))\n.catch((err) =\u003e {throw err})\n\n//innerJoin\nclass Cuentas {\n    cuenta_id_pk = 'int not null unique'\n    nombre = ''\n    email = ''\n    user_id_fk = ''\n}\nop.innerJoin({local_op: [\"id_pk\", \"nombre\"], ref_op: [\"nombre, email\"]}, new Cuentas(), 'cuentas', 'consulta')\n.then((res) =\u003e console.log(res))\n.catch((err) =\u003e {throw Error(err)})\n```\n- Using prepared statements\n```js\n//dependencias\nimport Operaciones from './services/Operations'\nimport User from \"./model/DbModel.js\"\nimport DbConfig from \"./utils/DbConfig.js\"\nimport DbConection from \"./services/DbConection\"\n\n\n// model instance\nconst model = new User()\nconst config = new DbConfig(\"database name\")\nmodel.initDB()\n\n// instance of database connection\nconst cursor = new DbConection(config).normal_conection()\n\n// database and table operations\nconst op = new Operaciones('consulta', 'users', cursor, model)\n\n// selecting all columns with pagination\nop.prepared_select_all(\n    {name: \"testing\", rol: \"worker\"},\n    \"and\", 10, 0\n)\n    .then((res) =\u003e console.log(res))\n    .catch((er) =\u003e console.error(er))\n\n// select by columns\nop.prepared_select(\n    ['name', 'email', 'rol'],\n    {name: \"testing\", rol: \"tester\"}, \"or\"\n)\n    .then((res) =\u003e console.log(res))\n    .catch((er) =\u003e console.error(er))\n\n// insert\nop.prepared_insert(\n    new User(\"testing\", \"testing@gmail.com\", \"asdf\", \"worker\")\n)\n    .then((res) =\u003e console.log(res))\n    .catch((er) =\u003e console.error(er))\n\n\n// update\nop.prepared_update(\n    {name: \"testing\", rol: \"tester\"},\n    ['name']\n)\n    .then((res) =\u003e console.log(res))\n    .catch((er) =\u003e console.error(er))\n\n\n```\n\n## Migration usage\n- migrations are make base on the database table model\n\u003e- you can make changes in the model and later run the migrations to update the database table fields\n```js\n//dependencias\nconst operations = require('./services/Operations')\nconst conn = require('./services/DbConection')\nconst User = require('./model/DbModel')\n\n// instances\nconst model = new User()\nconst op = new operations('db_name', 'tb_name', conn.normal_conection(), model)\n\n// make migrations\nop.make_migrations()\n.then((res) =\u003e {return res})\n```\n## Migration features \n- [x] create database\n- [x] create table base on javascript classes as models\n- [x] add, rename, delete, modify columns\n- [x] dynamic loading of migrations\n\n## Make relationships\n\n### Foreign key\n\u003e- when you declara a *FK* use the following style: `name_id_fk`.\n### Primary key\n\u003e- when you declare a *PK* use the following style: `id_pk`\n\n\n\u003e- the relations in the models looks like:\n```js\nclass Cuenta{\n    user_id_fk = '' // foreign key\n}\n\nclass User{\n    id_pk = '' // promary key\n}\n```\n\n## Relationship usage\n\n```js\n//modelos\nconst foreignModel = new User()\nconst primaryModel = new Cuenta()\n\n//operaciones\nconst userOP = new operations(database, table, conexión, foreignModel)\nconst cuentaOP = new opreations(database, table, conexion, primaryModel)\n\nuserOP.make_migrations(new Cuenta(), \"cuenta_table_name\")\n.then((res) =\u003e { return res })\n.cathc((err) =\u003e { throw err })\n```\n\n---\n\n# Disclaimer\n- this project is for educational purposes.\n- security issues are not taken into account.\n- Use it at your own risk.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falfonsog-dev%2Form-eje","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falfonsog-dev%2Form-eje","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falfonsog-dev%2Form-eje/lists"}