Registry / database / sequelize-mysql-timestamp

sequelize-mysql-timestamp

JSON →
library1.4.0jsnpmunverified

Adds MySQL TIMESTAMP column support to Sequelize.js. Current stable version 1.4.0 supports Sequelize 3.x and 4.x. It converts TIMESTAMP values to JavaScript Date objects or epoch integers, handling timezone-aware storage. Key differentiator: Sequelize natively only supports DATETIME for MySQL; this library fills the gap for legacy schemas or apps requiring absolute time storage without timezone conversion. Note the Year 2038 problem and limited date range.

npm install sequelize-mysql-timestamp
INSTALL
IMPORT
SIG · SEQUELIZE-MYSQL-TI
S
sequelize-mysql-timestamp
databasejavascriptv1.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sequelize-mysql-timestamp
const TIMESTAMP = require('sequelize-mysql-timestamp')(sequelize);
const TIMESTAMP = require('sequelize-mysql-timestamp');
The default export is a function that must be called with a Sequelize instance.
TIMESTAMP
import TIMESTAMP from 'sequelize-mysql-timestamp';
TypeScript ships types; use default import then call with sequelize instance.
sequelize-mysql-timestamp
const { TIMESTAMP } = require('sequelize-mysql-timestamp')(sequelize);
const { TIMESTAMP } = require('sequelize-mysql-timestamp');
Destructuring only works after calling the factory function.

Shows initializing the library, defining a model with TIMESTAMP column, and syncing.

const Sequelize = require('sequelize'); const sequelize = new Sequelize('database', 'username', 'password', { host: 'localhost', dialect: 'mysql' }); const TIMESTAMP = require('sequelize-mysql-timestamp')(sequelize); const User = sequelize.define('User', { username: Sequelize.STRING, hire_date: TIMESTAMP }); User.sync({ force: true }).then(() => User.create({ username: 'john', hire_date: new Date('2020-01-01') }));
Debug
Known issues
gotchaWhen using Sequelize $between operator, values are not passed through the TIMESTAMP type. Use raw UTC strings instead.
fix
Use string values in UTC format for $between: { hire_date: { $between: ['2016-01-01 00:00:00', '2016-01-31 23:59:59'] }}
affects: >=1.0.0
deprecatedOnly supports Sequelize 3.x and 4.x prerelease. Not compatible with Sequelize 5+.
fix
Upgrade to Sequelize 5+ native TIMESTAMP support or find alternative library.
affects: >=1.0.0
gotchaPassing string date values without timezone will be interpreted as local time, causing data inconsistency.
fix
Always pass Date objects, epoch integers, or Moment.js objects. Suppress warning with { warnings: false } option.
affects: >=1.0.0
breakingMySQL TIMESTAMP type only supports dates from 1970 to 2038. Applications storing dates outside this range will fail.
fix
Use DATETIME instead for dates outside the range, or migrate to a different data type.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Sequelize is not a constructor
Requiring sequelize-mysql-timestamp without first instantiating Sequelize.
fix
Ensure you create a Sequelize instance first, then pass it to the factory function.
Error: Unknown type TIMESTAMP
Using TIMESTAMP directly from the package without calling the factory function.
fix
Call require('sequelize-mysql-timestamp')(sequelize) to get the data type.
SequelizeDatabaseError: Data too long for column 'hire_date'
Passing a date beyond the TIMESTAMP range (2038-01-19).
fix
Use DATETIME for dates beyond 2038 or convert to epoch timestamp.
Upgrade
Version history
1.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Meta
1
Resources
sequelize-mysql-timestamp — npm install sequelize-mysql-timestamp · libregistry