sequelize 用于PostgreSQL,MySQL,SQLite和MSSQL的Node.js / io.js ORM
安装
Sequelize可通过NPM获得。
$ npm install --save sequelize # And one of the following:
$ npm install --save pg pg-hstore
$ npm install --save mysql // For both mysql and mariadb dialects
$ npm install --save sqlite3
$ npm install --save tedious // MSSQL
建立连接
Sequelize将在初始化时设置一个连接池,因此理想情况下只应为每个数据库创建一个实例。
var sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect: 'mysql'|'mariadb'|'sqlite'|'postgres'|'mssql', pool: {
max: 5,
min: 0,
idle: 10000
}, // SQLite only
storage: 'path/to/database.sqlite'
}); // Or you can simply use a connection uri
var sequelize = new Sequelize('postgres://user:pass@example.com:5432/dbname');
你的第一个模型
模型使用sequelize.define('name', {attributes}, {options})
。
var User = sequelize.define('user', {
firstName: {
type: Sequelize.STRING,
field: 'first_name' // Will result in an attribute that is firstName when user facing but first_name in the database
},
lastName: {
type: Sequelize.STRING
}
}, {
freezeTableName: true // Model tableName will be the same as the model name
}); User.sync({force: true}).then(function () {
// Table created
return User.create({
firstName: 'John',
lastName: 'Hancock'
});
});
参考链接:https://sequelize.readthedocs.io/en/v3/docs/getting-started/#setting-up-a-connection
sequelize 用于PostgreSQL,MySQL,SQLite和MSSQL的Node.js / io.js ORM的更多相关文章
- 在node.js中,使用基于ORM架构的Sequelize,操作mysql数据库之增删改查
Sequelize是一个基于promise的关系型数据库ORM框架,这个库完全采用JavaScript开发并且能够用在Node.JS环境中,易于使用,支持多SQL方言(dialect),.它当前支持M ...
- [转]在node.js中,使用基于ORM架构的Sequelize,操作mysql数据库之增删改查
本文转自:https://www.cnblogs.com/kongxianghai/p/5582661.html Sequelize是一个基于promise的关系型数据库ORM框架,这个库完全采用Ja ...
- 关于PDF.NET开发框架对Mysql Sqlite PostgreSQL数据库分页支持的个人看法
关于PDF.NET开发框架的名字由来 在设计www.pwmis.com站点的时候,考虑到架构的兼容性和将来升级的可能性,最重要的是没有足够的时间去为网站添加和维护很多复杂的程序,所以在借鉴前人成功经 ...
- 开源数据库 H2, HSQLDB, DERBY, PostgreSQL, MySQL区别/对比图表( 附加翻译) h2数据库
开源数据库 H2, HSQLDB, DERBY, PostgreSQL, MySQL区别/对比图表 浪天涯博主翻译: referential integrity 参考完整性transactions 事 ...
- SpringBoot配置多数据源Mysql+Sqlite
配置了一下druid的多数据源配置,尝试了很多方法,Spring boot关于对Mysql和Sqlite多数据源的配置,记录下来: 涉及技术点: Springboot + Druid + Mysq ...
- Fluent NHibernate and Mysql,SQLite,PostgreSQL
http://codeofrob.com/entries/sqlite-csharp-and-nhibernate.html https://code.google.com/archive/p/csh ...
- Redis/Mysql/SQLite/MongoDB 数据库对比
一.Redis: redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(so ...
- 数据库使用:sql server/mysql/sqlite
本科学过sql server数据库,上研刚开始在做研究时自己想点子自己做,为了简便使用了论文中看到的一个简易数据库sqlite存储使用数据.后来随着数据量的增长,以及数据处理的需求sqlite速度明显 ...
- Entity Framework 6连接Postgresql、SQLite、LocalDB的注意事项和配置文件
Postgresql Postgresql支持Code First的方式自动生成表,不过默认的模式是dbo而不是public,而且还可以自动生成自增主键. <?xml version=" ...
随机推荐
- 修复 Xcode 错误 “The identity used to sign the executable is no longer valid”
如图: 解决方法来自:http://stackoverflow.com/questions/7088441/the-identity-used-to-sign-the-executable-is-no ...
- cassandra 集群并发测试脚本
prepare: create keyspace ycsb WITH REPLICATION = { }; USE ycsb; CREATE TABLE users ( firstname text, ...
- Redis源码解析(1)——源码目录介绍
概念 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合)和zset(有序集合).这些 ...
- Django-进阶
分页 Django的分页器(paginator) view from django.shortcuts import render,HttpResponse # Create your views h ...
- C++ const 常量和常指针
常量,该指针所指向的值为只读 ; const int * p = &a; 常指针,该指针的值为只读,不可再指向其他地址 const * const p = &a; 常值,常指针 con ...
- LeetCode Binary Tree Tilt
原题链接在这里:https://leetcode.com/problems/binary-tree-tilt/description/ 题目: Given a binary tree, return ...
- poj2374 Fence Obstacle Course[线段树+DP]
https://vjudge.net/problem/POJ-2374 吐槽.在这题上面磕了许久..英文不好题面读错了qwq,写了个错的算法搞了很久..A掉之后瞥了一眼众多julao题解,**,怎么想 ...
- [Wc2009]shortest
传送门 终于把这题过了,了了我两年前写堵塞的交通一晚上无果的心结 因为是6要注意蛇皮走位啊!!这种-> S //Achen #include<bits/stdc++.h> #defi ...
- vlan之间Hybrid端口配置
要求:1.PC1和PC2不能互相访问,但是都能访问PC3 SW1配置:vlan batch 10 20 100 interface Ethernet0/0/1 ...
- [转载]Linux内核list_head学习(二)
前一篇文章讨论了list_head 结构的基本结构和实现原理,本文主要介绍一下实例代码. 自己如果想在应用程序中使用list_head 的相应操作(当然应该没人使用了,C++ STL提供了list 用 ...