简体   繁体   English

NodeJS 和 Sequelize,findOne 问题

[英]NodeJS and Sequelize, findOne issue

I'm using NodeJS 10.15 and Sequelize 3.24.3 ( sequelize ).我正在使用 NodeJS 10.15 和 Sequelize 3.24.3 ( sequelize )。

I'm just trying to check if a picture is already uploaded (to the db) checking some values, but it seems it cannot execute the query (no error, no warning, nothing, it just doesn't go on, it seems blocked by something).我只是想检查一张图片是否已经上传(到数据库)检查一些值,但它似乎无法执行查询(没有错误,没有警告,什么都没有,它只是没有打开 go,它似乎被阻止了通过某事)。
I'm using a transaction too (there are few inserts and update before and after this function), but it should work according to the documentation.我也在使用事务(在此功能之前和之后几乎没有插入和更新),但它应该根据文档工作。
This is the function这是 function

//Just getting tables from the db, it's working in other parts of the project
const models = require('../../models_newdb');

var filenameAlreadyPresent = function(insertInfo) {
    return new Promise(function(resolve, reject) {
        return models.ReportingPicture.findOne({
            transaction: insertInfo.transaction, 
            where: {
                InspectionGroup_ID: insertInfo.insertInfo.inspectionGroupID,
                Building_ID: insertInfo.insertInfo.buildingID,
                FileName: insertInfo.returnInfo.fileName
            }
        })
        .then(function (results) {
            console.log(results);
        })
        .catch(error => { return reject(error); });
    })
    .catch(error => { throw error; });
}

Inside insertInfo we can find all values we need (including transaction).insertInfo ,我们可以找到我们需要的所有值(包括事务)。 An example is:一个例子是:

InspectionGroup_ID: 33291
Building_ID: 6731
FileName: 33291_FG22502GC1_1638882304007.jpg

Any suggestion?有什么建议吗?



UPDATE: this is a console.log of insertInfo.transaction (the 3 dot notation is to hide some project information for my client, dont want to share those, but they are for the project, nothing related to the transaction)更新:这是insertInfo.transaction的console.log(3点符号是为我的客户隐藏一些项目信息,不想分享这些,但它们是用于项目的,与事务无关)

Transaction {
  sequelize:
   Sequelize {
     options:
      { dialect: 'mssql',
        dialectModulePath: null,
        host: '192.168.1.13',
        protocol: 'tcp',
        define: {},
        query: {},
        sync: {},
        timezone: 'Europe/Rome',
        logging: false,
        omitNull: false,
        native: false,
        replication: false,
        ssl: undefined,
        pool: [Object],
        quoteIdentifiers: true,
        hooks: {},
        retry: [Object],
        transactionType: 'DEFERRED',
        isolationLevel: 'REPEATABLE READ',
        databaseVersion: '15.0.2000',
        typeValidation: false,
        benchmark: false,
        server: '192.168.1.13',
        dialectOptions: [Object] },
     config: { ... },
     dialect:
      MssqlDialect {
        sequelize: [Circular],
        connectionManager: [ConnectionManager],
        QueryGenerator: [Object] },
     models: { ... },
     modelManager: ModelManager { models: [Array], sequelize: [Circular] },
     connectionManager:
      ConnectionManager {
        sequelize: [Circular],
        config: [Object],
        dialect: [MssqlDialect],
        versionPromise: null,
        dialectName: 'mssql',
        onProcessExit: [Function: bound ],
        lib: [Object],
        pool: [Pool] },
     importCache: { ... },
     test:
      { '$trackRunningQueries': false,
        '$runningQueries': 0,
        trackRunningQueries: [Function: trackRunningQueries],
        verifyNoRunningQueries: [Function: verifyNoRunningQueries] },
     queryInterface:
      QueryInterface { sequelize: [Circular], QueryGenerator: [Object] } },
  savepoints: [],
  options:
   { autocommit: true,
     type: 'DEFERRED',
     isolationLevel: 'REPEATABLE READ',
     readOnly: false },
  parent: undefined,
  id: 'fb84f7cbbc75cd637099',
  name: undefined,
  connection:
   ResourceLock {
     resource:
      Connection {
        _events: [Object],
        _eventsCount: 2,
        _maxListeners: undefined,
        config: [Object],
        reset: [Function: bound reset],
        socketClose: [Function: bound socketClose],
        socketEnd: [Function: bound socketEnd],
        socketConnect: [Function: bound socketConnect],
        socketError: [Function: bound socketError],
        requestTimeout: [Function: bound requestTimeout],
        connectTimeout: [Function: bound connectTimeout],
        debug: [Debug],
        tokenStreamParser: [Parser],
        inTransaction: true,
        transactionDescriptors: [Array],
        state: [Object],
        connectTimer:
         Timeout {
           _called: false,
           _idleTimeout: -1,
           _idlePrev: null,
           _idleNext: null,
           _idleStart: 3975,
           _onTimeout: null,
           _timerArgs: undefined,
           _repeat: null,
           _destroyed: false,
           [Symbol(unrefed)]: false,
           [Symbol(asyncId)]: 3275,
           [Symbol(triggerId)]: 3221 },
        lib: [Object],
        socket: [Socket],
        messageIo: [MessageIO],
        closed: false,
        messageBuffer:
         <Buffer 00 00 1a 00 06 01 00 20 00 01 02 00 21 00 01 03 00 22 00 00 04 00 22 00 01 ff 0f 00 07 d0 00 00 02 00 00>,
        routingData: undefined,
        loggedIn: true,
        isSqlBatch: false,
        request: undefined,
        requestTimer: undefined,
        resetConnectionOnNextRequest: false,
        procReturnStatusValue: undefined },
     previous:
      Promise [Object] {
        _bitField: 33554432,
        _fulfillmentHandler0: undefined,
        _rejectionHandler0: [Connection],
        _promise0: undefined,
        _receiver0: undefined },
     uuid: 'fb84f7cbbc75cd637099' } 
}

If you're sure insertInfo.transaction stores the correct transaction then just remove the mix of Promise and then/catch because findOne already returns Promise :如果您确定insertInfo.transaction存储了正确的事务,那么只需删除Promisethen/catch的组合,因为findOne已经返回Promise

var filenameAlreadyPresent = function(insertInfo) {
     return models.ReportingPicture.findOne({
         transaction: insertInfo.transaction, 
         where: {
             InspectionGroup_ID: insertInfo.insertInfo.inspectionGroupID,
             Building_ID: insertInfo.insertInfo.buildingID,
             FileName: insertInfo.returnInfo.fileName
         }
     })
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM