<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # orm2 中文文檔 > 譯者:[飛龍](https://github.com/wizardforcel) > 來源:[Object Relational Mapping](https://github.com/dresende/node-orm2/blob/master/Readme.md) ## 安裝 ``` npm install orm ``` ## 所支持的Node.js版本 支持 0.8, 0.10, 0.12, iojs-1.5 。 `0.10.x`,`0.12.x` 和 `iojs-1.5` 版本的測試在 [Travis CI](https://travis-ci.org/) 上運行。如果你想要的話,可以在本地運行測試: ``` npm test ``` ## DBMS 支持 + MySQL & MariaDB + PostgreSQL + Amazon Redshift + SQLite + MongoDB (beta版,到現在為止缺少聚合) ## 特性 + 創建模型,同步,刪除,批量創建,獲取,查找,移除,計數,聚合函數 + 創建模型的關聯,查找,檢查,創建和移除 + 定義自定義的驗證器(有一些內建的驗證器,會在保存之前檢查實例的屬性 -- 詳見[enforce](http://github.com/dresende/node-enforce) + 模型實例的緩存和一致性(兩次獲取表中的一行,獲取到相同的對象,修改其中一個就是修改全部) + 插件:[MySQL FTS](http://dresende.github.io/node-orm-mysql-fts),[Pagination](http://dresende.github.io/node-orm-paging) (分頁),[Transaction](http://dresende.github.io/node-orm-transaction) (事務),[Timestamps](http://github.com/SPARTAN563/node-orm-timestamps) (時間戳),[Migrations](https://github.com/locomote/node-migrate-orm2) (遷移) ## 介紹 這是一個 Node.js 對象關系映射模塊。 示例: ``` var orm = require("orm"); orm.connect("mysql://username:password@host/database", function (err, db) { if (err) throw err; var Person = db.define("person", { name : String, surname : String, age : Number, // FLOAT male : Boolean, continent : [ "Europe", "America", "Asia", "Africa", "Australia", "Antartica" ], // ENUM type photo : Buffer, // BLOB/BINARY data : Object // JSON encoded }, { methods: { fullName: function () { return this.name + ' ' + this.surname; } }, validations: { age: orm.enforce.ranges.number(18, undefined, "under-age") } }); // add the table to the database db.sync(function(err) { if (err) throw err; // add a row to the person table Person.create({ id: 1, name: "John", surname: "Doe", age: 27 }, function(err) { if (err) throw err; // query the person table by surname Person.find({ surname: "Doe" }, function (err, people) { // SQL: "SELECT * FROM person WHERE surname = 'Doe'" if (err) throw err; console.log("People found: %d", people.length); console.log("First person: %s, age %d", people[0].fullName(), people[0].age); people[0].age = 16; people[0].save(function (err) { // err.msg = "under-age"; }); }); }); }); }); ``` ## Promise 你可以使用[開啟Promise的包裝庫](https://github.com/rafaelkaufmann/q-orm)。 ## Express 如果你使用了Express,你可能想使用這一簡單的中間件,使集成變得更容易。 ``` var express = require('express'); var orm = require('orm'); var app = express(); app.use(orm.express("mysql://username:password@host/database", { define: function (db, models, next) { models.person = db.define("person", { ... }); next(); } })); app.listen(80); app.get("/", function (req, res) { // req.models is a reference to models used above in define() req.models.person.find(...); }); ``` 你可以多次調用`orm.express`來獲取多個數據庫的連接。在多個連接之間定義的模型會在`req.models`中連接。**不要忘記在`app.use(app.router)`之前使用它,最好在你的公共素材文件夾之后。** ## 示例 請見[`examples/anontxt`](https://github.com/dresende/node-orm2/tree/master/examples/anontxt),里面有一個基于express的應用示例。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看