Giter VIP home page Giter VIP logo

demo's Introduction

Description

Uses Node v16.13.1

This repo demonstrates the unexpected mutation of an array when it is passed into an insertQueryBuilder to be inserted into a sqlite db. In this scenario I created an array of 4 objects to be inserted. Each object consist of a message and a date. After the insert, the original array has it's objected mutated. The objects now have their updatedAt dates switched. Note this does not happen every single time, so you may need a few runs to get this result.

VALUES BEFORE INSERT [
  // HELLO + T00
  { message: 'hello', updatedAt: 2022-05-31T00:00:00.000Z },
  // WORLD + T05
  { message: 'world', updatedAt: 2022-05-31T05:00:00.000Z },
  // BONJOUR + T10
  { message: 'bonjour', updatedAt: 2022-05-31T10:00:00.000Z },
  // LE MONDE + T15
  { message: 'le monde', updatedAt: 2022-05-31T15:00:00.000Z }
]
VALUES AFTER INSERT [
  // HELLO + T10
  {
    message: 'hello',
    updatedAt: 2022-05-31T10:00:00.000Z,
    id: '43c5c4f4-bde1-4f1f-9e87-32aa941172b1'
  },
  // WORLD + T00
  {
    message: 'world',
    updatedAt: 2022-05-31T00:00:00.000Z,
    id: '592bd027-9889-4ad2-81ee-88e1af378740'
  },
  // BONJOUR + T15
  {
    message: 'bonjour',
    updatedAt: 2022-05-31T15:00:00.000Z,
    id: '68d381ce-e428-4570-960d-34504eefc30b'
  },
  // LE MONDE + T05
  {
    message: 'le monde',
    updatedAt: 2022-05-31T05:00:00.000Z,
    id: '6d9ba257-6705-4433-813b-45b530832700'
  }
]
INSERT RESULTS InsertResult {
  identifiers: [
    { id: '43c5c4f4-bde1-4f1f-9e87-32aa941172b1' },
    { id: '592bd027-9889-4ad2-81ee-88e1af378740' },
    { id: '68d381ce-e428-4570-960d-34504eefc30b' },
    { id: '6d9ba257-6705-4433-813b-45b530832700' }
  ],
  generatedMaps: [
    {
      id: '43c5c4f4-bde1-4f1f-9e87-32aa941172b1',
      updatedAt: 2022-05-31T10:00:00.000Z
    },
    {
      id: '592bd027-9889-4ad2-81ee-88e1af378740',
      updatedAt: 2022-05-31T00:00:00.000Z
    },
    {
      id: '68d381ce-e428-4570-960d-34504eefc30b',
      updatedAt: 2022-05-31T15:00:00.000Z
    },
    {
      id: '6d9ba257-6705-4433-813b-45b530832700',
      updatedAt: 2022-05-31T05:00:00.000Z
    }
  ],
  raw: 4
}
VALUES RETRIEVED FROM DB [
  // HELLO + T00
  TestModel {
    id: '592bd027-9889-4ad2-81ee-88e1af378740',
    message: 'hello',
    updatedAt: 2022-05-31T00:00:00.000Z
  },
  // WORLD + T05
  TestModel {
    id: '6d9ba257-6705-4433-813b-45b530832700',
    message: 'world',
    updatedAt: 2022-05-31T05:00:00.000Z
  },
  // BONJOUR + T10
  TestModel {
    id: '43c5c4f4-bde1-4f1f-9e87-32aa941172b1',
    message: 'bonjour',
    updatedAt: 2022-05-31T10:00:00.000Z
  },
  // LE MONDE + T15
  TestModel {
    id: '68d381ce-e428-4570-960d-34504eefc30b',
    message: 'le monde',
    updatedAt: 2022-05-31T15:00:00.000Z
  }
]

How to Run

npm install
npm run build
node lib/problem.js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.