Questions tagged [sequelize.js]

The Sequelize library provides an ORM (Object-Relational-Mapper) for Node.js, written entirely in JavaScript. Provides easy mapping for MySQL, MariaDB, SQLite, PostgreSQL and SQL Server.

The Sequelize library provides an ORM (Object-Relational-Mapper) for Node.js, written entirely in JavaScript. Provides easy mapping for , , , and .

It's well maintained and has lots of built-in features for dealing with the database, including transaction support, relations, eager and lazy loading, read replication.

Features

  • Schema definition
  • Schema synchronization/dropping
  • Easy definition of class/instance methods
  • Instance saving/updating/dropping
  • Asynchronous library
  • Associations
  • Importing definitions from single files

Useful links


Related tags :

12347 questions
256
votes
10 answers

Prevent Sequelize from outputting SQL to the console on execution of query?

I have a function to retrieve a user's profile. app.get('/api/user/profile', function (request, response) { // Create the default error container var error = new Error(); var User = db.User; User.find({ where: { emailAddress:…
thenetimp
  • 9,487
  • 5
  • 29
  • 42
184
votes
21 answers

How to update a record using sequelize for node?

I'm creating a RESTful API with NodeJS, express, express-resource, and Sequelize that is used to manage datasets stored in a MySQL database. I'm trying to figure out how to properly update a record using Sequelize. I create a model: module.exports =…
a_arias
  • 3,036
  • 2
  • 21
  • 20
168
votes
5 answers

How to make join queries using Sequelize on Node.js

I am using sequelize ORM; everything is great and clean, but I had a problem when I use it with join queries. I have two models: users and posts. var User = db.seq.define('User',{ username: { type: db.Sequelize.STRING}, email: { type:…
Jose Sosa
  • 2,157
  • 3
  • 17
  • 18
166
votes
12 answers

Sequelize.js: how to use migrations and sync

I'm close to having my project ready to launch. I have big plans for after launch and the database structure is going to change -- new columns in existing tables as well as new tables, and new associations to existing and new models. I haven't…
tremby
  • 9,541
  • 4
  • 55
  • 74
152
votes
4 answers

How can I see the SQL generated by Sequelize.js?

I want to see the SQL commands that are sent to the PostgreSQL server because I need to check if they are correct. In particular, I am interested in the table creation commands. For instance, ActiveRecord (Ruby) prints its SQL statements to standard…
ideaboxer
  • 3,863
  • 8
  • 43
  • 62
143
votes
12 answers

Sequelize, convert entity to plain object

I'm not very familiar with javascript, and stunning, because i can't add new property, to object, that fetched from database using ORM names Sequelize.js. To avoid this, i use this hack: db.Sensors.findAll({ where: { nodeid: node.nodeid …
Ruslan
  • 14,229
  • 8
  • 49
  • 67
142
votes
9 answers

sequelize findAll sort order in nodejs

I'm trying to output all object list from database with sequelize as follow and want to get data are sorted out as I added id in where clause. exports.getStaticCompanies = function () { return Company.findAll({ where: { id:…
PPShein
  • 13,309
  • 42
  • 142
  • 227
140
votes
14 answers

Sequelize.js delete query?

Is there a way to write a delete/deleteAll query like findAll? For example I want to do something like this (assuming MyModel is a Sequelize model...): MyModel.deleteAll({ where: ['some_field != ?', something] }) .on('success', function() { /*…
lakenen
  • 3,436
  • 5
  • 27
  • 39
140
votes
4 answers

How to make Sequelize use singular table names

I have an model called User but Sequelize looks for the table USERS whenever I am trying to save in the DB. Does anyone know how to set Sequelize to use singular table names? Thanks.
user3152350
139
votes
7 answers

Sequelize Unknown column '*.createdAt' in 'field list'

I'm getting a Unknown column 'userDetails.createdAt' in 'field list' When trying to fetch with association. Using findAll without association works fine. My code is as follows: var userDetails = sequelize.define('userDetails', { userId…
David Limkys
  • 4,907
  • 5
  • 26
  • 38
131
votes
11 answers

How to organize a node app that uses sequelize?

I am looking for an example nodejs app that uses the sequelize ORM. My main concern is that it seems next to impossible to define your models in separate js files if those models have complex relationships to one another because of require()…
mkoryak
  • 57,086
  • 61
  • 201
  • 257
125
votes
11 answers

How to auto generate migrations with Sequelize CLI from Sequelize models?

I have a set of Sequelize models. I want to use migrations, not DB Sync. Sequelize CLI seems to be able to do this, according to this article: "When you use the CLI for the model generation, you will gain the migration scripts for free as well." How…
Michael Schmidt
  • 3,391
  • 5
  • 34
  • 39
118
votes
9 answers

Sequelize OR condition object

By creating object like this var condition= { where: { LastName:"Doe", FirstName:["John","Jane"], Age:{ gt:18 } } } and pass it in Student.findAll(condition) .success(function(students){ }) It could…
Morio
  • 8,463
  • 5
  • 25
  • 29
112
votes
4 answers

sequelize table without column 'id'

I have the following sequelize definition of a table: AcademyModule = sequelize.define('academy_module', { academy_id: DataTypes.INTEGER, module_id: DataTypes.INTEGER, module_module_type_id: DataTypes.INTEGER, …
Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364
101
votes
5 answers

Sequelize Where statement with date

I am using Sequelize as my backend ORM. Now I wish to do some WHERE operations on a Date. More specifically, I want to get all data where a date is between now and 7 days ago. The problem is that the documentation does not specify which operations…
Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364
1
2 3
99 100