Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize use camel case in JS but underscores in table names

Tags:

sequelize.js

Is it possible to have column names be underscored (postgres) but have the JavaScript getters be camelCase per language standards?

like image 583
futbolpal Avatar asked Sep 17 '13 19:09

futbolpal


People also ask

How do you make a Sequelize use singular table names?

const People = sequelize. define('people', { name: DataTypes. STRING, }, { hooks: { beforeCount (options) { options. raw = true; } }, tableName: 'people', name: { singular: 'person', plural: 'people' } });

What options does Sequelize provide when it comes to naming tables and fields?

Without the underscored option, Sequelize would automatically define: A createdAt attribute for each model, pointing to a column named createdAt in each table. An updatedAt attribute for each model, pointing to a column named updatedAt in each table.

Is JS camelCase or snake case?

camelCase is used by JavaScript itself, by jQuery, and other JavaScript libraries.


1 Answers

For anyone finding this later on it's now possible to explicitely define what the database field should be named:

var User = sequelize.define('user', {   isAdmin: {     type: DataTypes.BOOLEAN,     field: 'is_admin'   } }); 
like image 116
Mick Hansen Avatar answered Sep 21 '22 09:09

Mick Hansen