0
votes

I'm using SQL Server 2005 and node.js with

"dependencies": {
    "sequelize": "^4.42.0",
    "tedious": "^5.0.3"
  }

And I'm trying to create this database

const con = require('./../dbo/connect');
const Processo = con.db.define('processo', {
    Id: {
        type: con.Sequelize.INTEGER,
        autoIncrement: true,
        primaryKey: true
    },
    Cavalo: { type: con.Sequelize.STRING },
    Reboque: { type: con.Sequelize.STRING },
    CNPJTransportadora: { type: con.Sequelize.STRING },
    Motorista: { type: con.Sequelize.STRING },
    CNH: { type: con.Sequelize.STRING },
    EntradaCarreta: { type: con.Sequelize.DATE },
    SaidaCarreta: { type: con.Sequelize.DATE },
    Tara: { type: con.Sequelize.DECIMAL(10, 3)  },
    PesoBruto: { type: con.Sequelize.DECIMAL(10, 3)  },
    Conteiner: { type: con.Sequelize.STRING },
    Dimensao: { type: con.Sequelize.STRING },
    IsoCode: { type: con.Sequelize.STRING },
    GMCI: { type: con.Sequelize.STRING },
    DT: { type: con.Sequelize.STRING },
    Navio: { type: con.Sequelize.STRING },
    Viagem: { type: con.Sequelize.STRING },
    Origem: { type: con.Sequelize.STRING },
    CodOrigem: { type: con.Sequelize.STRING },
    Destino: { type: con.Sequelize.STRING },
    CodDestino: { type: con.Sequelize.STRING },
    Regime: { type: con.Sequelize.STRING }
});
Processo.sync();
module.exports = {
    Processo,
    Sequelize:con.Sequelize
};

But when run the Sync function, I get this error:

Unhandled rejection SequelizeDatabaseError: Column, parameter, or variable #7: Cannot find data type DATETIMEOFFSET. at Query.formatError (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\node_modules\s equelize\lib\dialects\mssql\query.js:315:12) at Request.connection.lib.Request [as userCallback] (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\r ecepcao-processo\node_modules\sequelize\lib\dialects\mssql\query.js:107:25) at Request.callback (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\node_modules\te dious\lib\request.js:37:27) at Connection.endOfMessageMarkerReceived (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-pro cesso\node_modules\tedious\lib\connection.js:2118:20) at Connection.dispatchEvent (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\node_mo dules\tedious\lib\connection.js:1136:36) at Parser.tokenStreamParser.on (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\node _modules\tedious\lib\connection.js:941:14) at Parser.emit (events.js:189:13) at Parser.parser.on.token (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\node_modu les\tedious\lib\token\token-stream-parser.js:27:14) at Parser.emit (events.js:189:13) at addChunk (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\node_modules\readable-s tream\lib_stream_readable.js:296:12) at readableAddChunk (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\node_modules\re adable-stream\lib_stream_readable.js:278:11) at Parser.Readable.push (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\node_module s\readable-stream\lib_stream_readable.js:239:10) at Parser.Transform.push (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\node_modul es\readable-stream\lib_stream_transform.js:139:32) at Parser.afterTransform (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\node_modul es\readable-stream\lib_stream_transform.js:88:10) at Parser._transform (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\node_modules\t edious\lib\token\stream-parser.js:41:7) at Parser.Transform._read (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\node_modu les\readable-stream\lib_stream_transform.js:177:10) at Parser.Transform._write (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\node_mod ules\readable-stream\lib_stream_transform.js:164:83) at doWrite (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\node_modules\readable-st ream\lib_stream_writable.js:405:139) at writeOrBuffer (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\node_modules\reada ble-stream\lib_stream_writable.js:394:5) at Parser.Writable.write (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\node_modul es\readable-stream\lib_stream_writable.js:303:11) at Parser.addEndOfMessageMarker (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\nod e_modules\tedious\lib\token\token-stream-parser.js:45:24) at Connection.message (C:\Users\tiago.santos\Desktop\Labs\diariamente-ts\node\gmci-e\recepcao-processo\node_modules\ tedious\lib\connection.js:2107:32)

1

1 Answers

0
votes

I know this far away of the best solution, but i solved this way:

'use strict';
const fs = require('fs');
const paths = {
    datatypes: `${__dirname}/../../node_modules/sequelize/lib/dialects/mssql/data-types.js`
};

async function rewriteFile(path, find, replace) {
    let data = fs.readFileSync(paths[path], 'utf-8');
    let newValue = data.replace(find, replace);
    return await fs.writeFileSync(paths[path], newValue, 'utf-8');
}
module.exports = {
    rewriteFile
}

And run bellow code before start express:

const sequelizeBug = require('./../api/helpers/sequelize-bug');
sequelizeBug.rewriteFile('datatypes', 'DATETIMEOFFSET','DATETIME');

if anyone have a best solution, i accept, thks.