Problem with the sequence to a mysql database

hello when sending these data it does not send them in a sequence, enter a delay before the db but I do not think it is a very good solution.

[
    {
        "id": "8ccfea43805ace69",
        "type": "inject",
        "z": "e3947d5bbc316eda",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 400,
        "y": 460,
        "wires": [
            [
                "e849f13f69419b06"
            ]
        ]
    },
    {
        "id": "e849f13f69419b06",
        "type": "XLSX-to-json",
        "z": "e3947d5bbc316eda",
        "name": "xlsx to json",
        "filepath": "C:\\Users\\MOLDURAS SUPERVICION\\Desktop\\excel.xlsx",
        "rangecell": "",
        "columnkey": "",
        "sheet": "",
        "x": 610,
        "y": 460,
        "wires": [
            [
                "6f104ba5f6b5b58a"
            ]
        ]
    },
    {
        "id": "6f104ba5f6b5b58a",
        "type": "split",
        "z": "e3947d5bbc316eda",
        "name": "",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 810,
        "y": 460,
        "wires": [
            [
                "6f9151785a193456"
            ]
        ]
    },
    {
        "id": "6f9151785a193456",
        "type": "function",
        "z": "e3947d5bbc316eda",
        "name": "function 182",
        "func": "\n\nfor (let i = 1; i < msg.payload.length; i++) {\n    let objeto = msg.payload[i];\n    let topic = `INSERT INTO ORDEN_DIA (linea, orden, sku, cant) VALUES (${objeto.linea}, ${objeto.orden}, '${objeto.sku}', ${objeto.cant})`;\n    \n    \n\n    node.send({\n        topic: topic,\n        payload: objeto\n    });\n}\n\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 990,
        "y": 460,
        "wires": [
            [
                "ac06eda445f90812"
            ]
        ]
    },
    {
        "id": "76c471d2987fea1c",
        "type": "debug",
        "z": "e3947d5bbc316eda",
        "name": "debug 276",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1390,
        "y": 460,
        "wires": []
    },
    {
        "id": "ac06eda445f90812",
        "type": "mysql",
        "z": "e3947d5bbc316eda",
        "mydb": "3149a60ea0bd0342",
        "name": "",
        "x": 1210,
        "y": 460,
        "wires": [
            [
                "76c471d2987fea1c"
            ]
        ]
    },
    {
        "id": "3149a60ea0bd0342",
        "type": "MySQLdatabase",
        "name": "",
        "host": "localhost",
        "port": "3306",
        "db": "datos2",
        "tz": "",
        "charset": "UTF8"
    }
]

Welcome to the forum @Andriuw

Can you explain what you mean by "it does not send them in a sequence"?

I would expect your code to send an INSERT statement for each of your array elements, in order (except element 0, which looks like column headings)

If you retrieve these records with a SELECT statement, the order is not guaranteed unless you have an ORDER BY clause.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.