{"_id":"mysql_node_orm","_rev":"5-c7e06c1261ef02f4e94dc348ecd66170","name":"mysql_node_orm","description":"A simple ActiveRecord like nodejs module for mysql","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"mysql_node_orm","version":"0.0.1","dependencies":{"mysql-libmysqlclient":"1.2.9","logging":"latest"},"devDependencies":{},"engines":{"node":">= 0.5.0"},"author":{"name":"Fatshotty","email":"fat@fatshotty.net","url":"https://github.com/fatshotty"},"description":"A simple ActiveRecord like nodejs module for mysql","homepage":"https://github.com/fatshotty/mysql_node_orm","repository":{"type":"git","url":"git://github.com/fatshotty/mysql_node_orm.git"},"main":"index","scripts":{"test":"jasmine-node --color --verbose spec/"},"_npmUser":{"name":"fatshotty","email":"fat@fatshotty.net"},"_id":"mysql_node_orm@0.0.1","optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.12","_nodeVersion":"v0.6.14","_defaultsLoaded":true,"dist":{"shasum":"eda37b57b2ce252140044472fcb585a24de6db27","tarball":"https://registry.npmjs.org/mysql_node_orm/-/mysql_node_orm-0.0.1.tgz","integrity":"sha512-ensoy6rQGZRph8eQGIbd+UfsfihsmTTYoCc9ZHkpkPyPwb+qlQc8+FOinW2htk2WOefXUwB3C+nJjj6YBezYrA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDbp+TGRWGhNUuZ+MOdbRKNizn6g0w/mmuxTem95Bv9+AiEAgAewSzEvkZuMibTR66uOzVhIMVT1xctFLh3DK9zXOAw="}]},"maintainers":[{"name":"fatshotty","email":"fat@fatshotty.net"}]}},"readme":"# mysql_node_orm\n\n## Purpose\n\nA simple `ActiveRecord` like nodejs module for `mysql` database.\n\nIt supports `has_many` and `belongs_to` relationship.\n\nYou can `find` and `find_by*` each field name.\n\n**Important**: it works synchronously.\n\n## Introduction\n\nThis module is based on Sannis's [node-mysql-libmysqlclient](https://github.com/Sannis/node-mysql-libmysqlclient).\n\nMysql_node_orm adds some simple features as ActiveRecord does.\n\nI'm working on it and I would to expand it also with your help.\n\nSo, do not hesitate to contact me for any question or doubts\n\nMy mind is open for any collaboration ;)\n\n## Installation\n\nFor installing this module use\n\n```\nnpm install mysql_node_orm\n```\n\n## Usage\n\nSee files in the `spec` folder for examples\n\n\n## Overview\nHaving a DB as ActiveRecord on Rails wants.\nYou can able to perform `select` `insert` and `update` using `Models` like instances.\n\n```javascript\nvar DataType = require('mysql_node_orm/lib/datatype');\nvar Adapter = require('mysql_node_orm');\n\nvar Author = Adapter.declare('Author', {\n  has_many: ['Book'],\n  destroy: [ 'Book' ],\n  fields: {\n    name: {\n      type: DataType.String,\n      unique: true\n    },\n    age: {\n      type: DataType.Int\n    }\n  }\n});\n\nBook = Adapter.declare('Book', {\n  belongs_to: ['Author'],\n  fields: {\n    name: {\n      type: DataType.String\n    },\n    pages_number: {\n      type: DataType.Int\n    }\n  },\n  methods:{\n    foo: function(bar){\n      this.test();\n      return 'foobar ' + bar;\n    },\n    test: function(){\n      return 'test method'\n    }\n  }\n});\n\nvar author = Author.find( 1 );\nvar books = author.books\n\nbook = new Book({\n  name: 'Foobar book'\n});\n\nbook.pages_number = 1024;\n\nbooks.push( book );\n\nauthor.save( true );\n\nAdapter.close();\n```\n\n\n### Adapter(host, user, pwd, database, port)\n* it is the main class\n\n```javascript\nvar Adapter = require('mysql_node_orm');\nvar adapter = new Adapter( 'localhost', 'root', 'password', 'db_name', 3306);\n```\n\n\n### DataType (used to declare the fields)\n* DataType.String           # the VARCHAR type\n* DataType.Int              # the INT type\n* DataType.Boolean          # the TYNINT type\n\n`(tmporarly incompleted)`\n\n```javascript\n// To use the datatype\nvar DataType = require('mysql_node_orm/lib/datatype')\n```\n\n### Model\n\n(Static methods)\n\n* `Model.find( id /* as NUM */ )`   # returns the instance of the model if found. Otherwise null\n* `Model.find( 'all' )`             # returns an Array instance contaning all model found by performing the `select`. Empty array if no record found\n* `Model.find( 'first' )`           # returns the instance of the model representing the first matched record if found. Otherwise null\n* `Model.find_by( where, options, limit )`\n#### where (Object)\n    ```javascipt\n    where = {\n      field_foo_name: field_foo_value,\n      field_bar_name: field_bar_value,\n    }\n    ```\n#### options (Object)\n    ```javascript\n    options = {\n      includes: ['table_foo_name', 'table_bar_name'],\n      joins: {\n        table_foo_name: {                       // INNER JOIN table_foo_name\n          field_bar_name: {                     // ON  field_bar_name\n            table_xxxx_name: 'field_xxxx_name'  // = table_xxxx_name.field_xxxx_name\n          }\n        }\n      }\n    }\n    ```\n#### limit (Number)    Used as `LIMIT` sql condition\n\n* `Model.find_by_foo_field_name( value )`     # return an Array containing the result of `select * from table_foo_name where FOO_FIELD_NAME = VALUE`. A single Model instance if field is declared as unique\n\n\n## Todo\n\nWhat I'm going to do:\n\n* has_many_through relations\n* DataType conversion\n* migrations\n\n* More documentation is coming... ;)\n\n\n## Done\n* Delete model and its `dependencies`\n* Implement events\n* Fields validation","maintainers":[{"name":"fatshotty","email":"fat@fatshotty.net"}],"time":{"modified":"2022-06-20T18:25:24.791Z","created":"2012-04-17T16:21:19.626Z","0.0.1":"2012-04-17T16:21:21.899Z"},"author":{"name":"Fatshotty","email":"fat@fatshotty.net","url":"https://github.com/fatshotty"},"repository":{"type":"git","url":"git://github.com/fatshotty/mysql_node_orm.git"}}