@isoftdata/universal-object-htp-utility
Advanced tools
+1
-2
| import { query } from '@isoftdata/utility-db' | ||
| import { multiRowUpsertQuery } from './shared.js' | ||
| import { multiRowUpsertQuery, query } from './shared.js' | ||
@@ -5,0 +4,0 @@ function convertCategory(categoryRow, productCode ) { |
+1
-2
@@ -1,3 +0,2 @@ | ||
| import { query } from '@isoftdata/utility-db' | ||
| import { multiRowUpsertQuery } from './shared.js' | ||
| import { multiRowUpsertQuery, query } from './shared.js' | ||
| // This still expects companyinfo_replikwando to be setup ahead of time | ||
@@ -4,0 +3,0 @@ function convertStore(row, productCode, companyInfoResults) { |
+2
-2
@@ -1,4 +0,4 @@ | ||
| import { query } from '@isoftdata/utility-db' | ||
| import { multiRowUpsertQuery } from './shared.js' | ||
| import { multiRowUpsertQuery, query } from './shared.js' | ||
| function convertCustomer(row, productCode ) { | ||
@@ -5,0 +5,0 @@ return { |
@@ -1,4 +0,4 @@ | ||
| import { query } from '@isoftdata/utility-db' | ||
| import { multiRowUpsertQuery } from './shared.js' | ||
| import { multiRowUpsertQuery, query } from './shared.js' | ||
| function convertCustomerAddress(row, productCode ) { | ||
@@ -5,0 +5,0 @@ return { |
@@ -1,4 +0,4 @@ | ||
| import { query } from '@isoftdata/utility-db' | ||
| import { multiRowUpsertQuery } from './shared.js' | ||
| import { multiRowUpsertQuery, query } from './shared.js' | ||
| function convertCustomerOption(row, productCode ) { | ||
@@ -5,0 +5,0 @@ return { |
@@ -1,4 +0,4 @@ | ||
| import { query } from '@isoftdata/utility-db' | ||
| import { multiRowUpsertQuery } from './shared.js' | ||
| import { multiRowUpsertQuery, query } from './shared.js' | ||
| function convertCustomerOptionValue(row, productCode ) { | ||
@@ -5,0 +5,0 @@ return { |
@@ -1,4 +0,4 @@ | ||
| import { query } from '@isoftdata/utility-db' | ||
| import { multiRowUpsertQuery } from './shared.js' | ||
| import { multiRowUpsertQuery, query } from './shared.js' | ||
| function convertCustomerPriceContract(row, productCode ) { | ||
@@ -5,0 +5,0 @@ return { |
+40
-28
| import _ from "lodash" | ||
| import mysql from 'mysql' | ||
| import mysql from 'mysql2/promise' | ||
| import pProps from 'p-props' | ||
| import { multiRowInsertQuery, multiRowUpsertQuery, query } from './shared.js' | ||
| import db from '@isoftdata/utility-db' | ||
| import { insertInventoryOptionListRows, upsertInventoryOptionListRows } from './inventoryOptionList.js' | ||
@@ -10,3 +11,2 @@ import { insertInventoryOptionRows, upsertInventoryOptionRows, deleteInventoryOptionRows } from './inventoryOption.js' | ||
| import { upsertInventorySourceRows, deleteInventorySourceData } from './inventorySource.js' | ||
| import { multiRowInsertQuery, multiRowUpsertQuery } from './shared.js' | ||
@@ -31,3 +31,3 @@ // Get partuse data for all of the rows being handled | ||
| } | ||
| const response = await db.query(htpConnection, queryOptions) | ||
| const response = await query(htpConnection, queryOptions) | ||
@@ -194,24 +194,31 @@ return response.map(row => ( | ||
| if (filteredRows.length) { | ||
| //Start Transaction | ||
| const connectionWithTransaction = await db.getTransactionFromPool(htpConnection) | ||
| // Try catch block for transaction handling | ||
| // Get a connection from the pool for transaction | ||
| const connection = await htpConnection.getConnection() | ||
| try { | ||
| // Start transaction | ||
| await connection.beginTransaction() | ||
| // Insert inventory rows first, return should be?? | ||
| const multiRowUpsertResponse = await multiRowUpsertQuery(connectionWithTransaction, 'inventory', filteredRows) | ||
| const multiRowUpsertResponse = await multiRowUpsertQuery(connection, 'inventory', filteredRows) | ||
| // call inventory option list stuff | ||
| const multiRowInventoryOptionListUpsertResponse = await upsertInventoryOptionListRows(connectionWithTransaction, filteredInventoryPartUseRows, productCode) | ||
| const multiRowInventoryOptionUpsertResponse = await upsertInventoryOptionRows(connectionWithTransaction, filteredInventoryPartUseRows, productCode) | ||
| const multiRowInventoryOptionListUpsertResponse = await upsertInventoryOptionListRows(connection, filteredInventoryPartUseRows, productCode) | ||
| const multiRowInventoryOptionUpsertResponse = await upsertInventoryOptionRows(connection, filteredInventoryPartUseRows, productCode) | ||
| // call inventory file and image stuff | ||
| const multiRowInventoryFileUpsertResponse = await upsertInventoryFileData(connectionWithTransaction, filteredInventoryPartUseRows, productCode) | ||
| const multiRowInventoryFileUpsertResponse = await upsertInventoryFileData(connection, filteredInventoryPartUseRows, productCode) | ||
| // call inventory source stuff | ||
| let multiRowInventorySourceUpsertResponse | ||
| if (settings.synchSource) { | ||
| multiRowInventorySourceUpsertResponse = await upsertInventorySourceRows(connectionWithTransaction, filteredInventoryPartUseRows, productCode) | ||
| multiRowInventorySourceUpsertResponse = await upsertInventorySourceRows(connection, filteredInventoryPartUseRows, productCode) | ||
| } | ||
| await db.commitAndRelease(connectionWithTransaction) | ||
| // Commit transaction | ||
| await connection.commit() | ||
| responses.push(`affected rows: inventory ${multiRowUpsertResponse?.affectedRows}, ${multiRowInventoryOptionListUpsertResponse}, ${multiRowInventoryOptionUpsertResponse}, ${[...multiRowInventoryFileUpsertResponse]}, ${multiRowInventorySourceUpsertResponse ? multiRowInventorySourceUpsertResponse : 'inventorysource affected rows: none' }`) | ||
| // Rollback transaction if there's an error | ||
| } catch (err) { | ||
| db.rollbackAndRelease(connectionWithTransaction) | ||
| // Rollback transaction on error | ||
| await connection.rollback() | ||
| throw err | ||
| } finally { | ||
| // Always release connection back to pool | ||
| connection.release() | ||
| } | ||
@@ -240,3 +247,3 @@ } else { | ||
| } | ||
| return await db.query(htpConnection, queryOptions) | ||
| return await query(htpConnection, queryOptions) | ||
| } | ||
@@ -297,25 +304,30 @@ | ||
| if (filteredRows.length) { | ||
| //Start Transaction | ||
| const connectionWithTransaction = await db.getTransactionFromPool(htpConnection) | ||
| // Try catch block for transaction handling | ||
| // Get a connection from the pool for transaction | ||
| const connection = await htpConnection.getConnection() | ||
| try { | ||
| // Start transaction | ||
| await connection.beginTransaction() | ||
| // Insert inventory rows first | ||
| const initialResponse = await pProps({ | ||
| inventoryInsertResponse: insertInventoryRows(connectionWithTransaction, filteredRows), | ||
| inventoryFileResponse: insertInventoryFileData(connectionWithTransaction, filteredInventoryPartUseRows, productCode), | ||
| inventoryOptionListResponse: insertInventoryOptionListRows(connectionWithTransaction, filteredInventoryPartUseRows, productCode), | ||
| inventorySourceUpsertResponse: settings.synchSource ? upsertInventorySourceRows(connectionWithTransaction, filteredInventoryPartUseRows, productCode) : Promise.resolve(null) | ||
| inventoryInsertResponse: insertInventoryRows(connection, filteredRows), | ||
| inventoryFileResponse: insertInventoryFileData(connection, filteredInventoryPartUseRows, productCode), | ||
| inventoryOptionListResponse: insertInventoryOptionListRows(connection, filteredInventoryPartUseRows, productCode), | ||
| inventorySourceUpsertResponse: settings.synchSource ? upsertInventorySourceRows(connection, filteredInventoryPartUseRows, productCode) : Promise.resolve(null) | ||
| }) | ||
| // This one has to be run after inventoryoptionlist since it needs to query for those rows | ||
| const inventoryOptionResponse = await insertInventoryOptionRows(connectionWithTransaction, filteredInventoryPartUseRows, productCode) | ||
| const inventoryOptionResponse = await insertInventoryOptionRows(connection, filteredInventoryPartUseRows, productCode) | ||
| await db.commitAndRelease(connectionWithTransaction) | ||
| // Commit transaction | ||
| await connection.commit() | ||
| responses.push(`affected rows: inventory ${initialResponse.inventoryInsertResponse?.affectedRows}, ${initialResponse.inventoryOptionListResponse}, ${inventoryOptionResponse}, ${initialResponse.inventoryFileResponse ? [...initialResponse.inventoryFileResponse] : ''}, ${initialResponse.inventorySourceUpsertResponse ? initialResponse.inventorySourceUpsertResponse : 'inventorysource affected rows: none' }`) | ||
| // responses.push(`affected rows: inventory ${inventoryInsertResponse.affectedRows}, ${inventoryOptionListResponse.affectedRows}, ${inventoryOptionResponse?.affectedRows}, ${inventoryFileResponse?.affectedRows}`) | ||
| // Rollback transaction if there's an error | ||
| } catch (err) { | ||
| db.rollbackAndRelease(connectionWithTransaction) | ||
| // Rollback transaction on error | ||
| await connection.rollback() | ||
| throw err | ||
| } finally { | ||
| // Always release connection back to pool | ||
| connection.release() | ||
| } | ||
@@ -322,0 +334,0 @@ } |
+2
-2
@@ -1,3 +0,3 @@ | ||
| import { query } from '@isoftdata/utility-db' | ||
| import { multiRowInsertQuery } from './shared.js' | ||
| import { query, multiRowInsertQuery } from './shared.js' | ||
| import pProps from 'p-props' | ||
@@ -4,0 +4,0 @@ |
@@ -1,4 +0,3 @@ | ||
| import { query, queryFirst } from '@isoftdata/utility-db' | ||
| import mysql from 'mysql' | ||
| import { multiRowInsertQuery } from './shared.js' | ||
| import mysql from 'mysql2/promise' | ||
| import { multiRowInsertQuery, query, queryFirst } from './shared.js' | ||
| import _ from 'lodash' | ||
@@ -5,0 +4,0 @@ |
@@ -1,5 +0,4 @@ | ||
| import { query, queryFirst } from "@isoftdata/utility-db" | ||
| import { multiRowInsertQuery } from './shared.js' | ||
| import { multiRowInsertQuery, query, queryFirst } from './shared.js' | ||
| import _ from "lodash" | ||
| import mysql from 'mysql' | ||
| import mysql from 'mysql2/promise' | ||
@@ -6,0 +5,0 @@ // Get partlistauthorityid and partuse from HTP using inventorytype name from universal inventory object |
@@ -1,3 +0,2 @@ | ||
| import { query } from '@isoftdata/utility-db' | ||
| import { multiRowUpsertQuery, multiRowInsertQuery } from './shared.js' | ||
| import { multiRowUpsertQuery, multiRowInsertQuery, query } from './shared.js' | ||
| import pProps from 'p-props' | ||
@@ -4,0 +3,0 @@ |
+3
-3
@@ -1,5 +0,5 @@ | ||
| import { query } from '@isoftdata/utility-db' | ||
| import { multiRowUpsertQuery } from './shared.js' | ||
| import mysql from 'mysql' | ||
| import { multiRowUpsertQuery, query } from './shared.js' | ||
| import mysql from 'mysql2/promise' | ||
| // TODO: Change naming to invmaster to match others | ||
@@ -6,0 +6,0 @@ function convertVehicle(vehicleRow, productCode) { |
+2
-3
@@ -1,4 +0,3 @@ | ||
| import { query } from '@isoftdata/utility-db' | ||
| import { multiRowInsertQuery, multiRowUpsertQuery } from './shared.js' | ||
| import mysql from 'mysql' | ||
| import { multiRowInsertQuery, multiRowUpsertQuery, query } from './shared.js' | ||
| import mysql from 'mysql2/promise' | ||
@@ -5,0 +4,0 @@ // Convert universal model object to HTP insertable row for mnfcrmod |
+2
-3
| { | ||
| "name": "@isoftdata/universal-object-htp-utility", | ||
| "version": "3.16.0", | ||
| "version": "3.17.0", | ||
| "description": "Functions to convert universal objects to htp schema", | ||
@@ -10,5 +10,4 @@ "main": "index.js", | ||
| "dependencies": { | ||
| "@isoftdata/utility-db": "^1.5.0", | ||
| "lodash": "^4.17.21", | ||
| "mysql": "^2.18.1", | ||
| "mysql2": "^3.16.0", | ||
| "p-props": "^6.0.0" | ||
@@ -15,0 +14,0 @@ }, |
@@ -1,3 +0,2 @@ | ||
| import { query } from '@isoftdata/utility-db' | ||
| import { multiRowUpsertQuery } from './shared.js' | ||
| import { multiRowUpsertQuery, query } from './shared.js' | ||
@@ -4,0 +3,0 @@ function convertPartListAuthorityMap(inventoryTypeRow, productCode) { |
+2
-3
@@ -1,7 +0,6 @@ | ||
| import { query } from '@isoftdata/utility-db' | ||
| import mysql from 'mysql' | ||
| import mysql from 'mysql2/promise' | ||
| import pProps from 'p-props' | ||
| import { upsertPartListAuthorityMapRows, deletePartListAuthorityMapRow } from './partListAuthority.js' | ||
| import { multiRowUpsertQuery } from './shared.js' | ||
| import { multiRowUpsertQuery, query } from './shared.js' | ||
@@ -8,0 +7,0 @@ function convertInventoryType(row, productCode) { |
@@ -1,3 +0,2 @@ | ||
| import { query } from '@isoftdata/utility-db' | ||
| import { multiRowUpsertQuery } from './shared.js' | ||
| import { multiRowUpsertQuery, query } from './shared.js' | ||
@@ -4,0 +3,0 @@ function convertSellPriceContract(row, productCode ) { |
+25
-2
@@ -1,3 +0,27 @@ | ||
| import {query} from '@isoftdata/utility-db' | ||
| export async function query(connection, queryOptions) { | ||
| // mysql2/promise returns [rows, fields] | ||
| // Both Pool and Connection have .query() method | ||
| // Pool.query() automatically manages connection get/release | ||
| const [rows] = await connection.query(queryOptions); | ||
| return rows; | ||
| } | ||
| export async function queryFirst(connection, queryOptions) { | ||
| // mysql2/promise returns [rows, fields] | ||
| // Both Pool and Connection have .query() method | ||
| // Pool.query() automatically manages connection get/release | ||
| const [rows] = await connection.query(queryOptions); | ||
| return rows[0] || null; | ||
| } | ||
| export async function write(connection, queryOptions) { | ||
| // mysql2/promise returns [ResultSetHeader, fields] for write operations | ||
| // ResultSetHeader contains: affectedRows, insertId, warningStatus, etc. | ||
| // Both Pool and Connection have .query() method | ||
| // Pool.query() automatically manages connection get/release | ||
| const [result] = await connection.query(queryOptions); | ||
| return result; | ||
| } | ||
| export async function upsertQuery(connection, table, row) { | ||
@@ -23,3 +47,2 @@ const queryOptions = { | ||
| } | ||
| //const sqlQuery = require('mysql').format(queryOptions.sql, queryOptions.values) | ||
| return await query(htpConnection, queryOptions) | ||
@@ -26,0 +49,0 @@ } |
| // Test to confirm that the Map implementation of convertManyInventoryOptionValue behaves the same as the original implementation | ||
| import assert from 'assert' | ||
| import mysql from 'mysql' | ||
| import mysql from 'mysql2/promise' | ||
@@ -208,3 +208,3 @@ // Original implementation of convertManyInventoryOptionValue | ||
| // Check each object in the arrays | ||
| for (let i = 0 i < sortedOriginal.length i++) { | ||
| for (let i = 0; i < sortedOriginal.length; i++) { | ||
| const originalObj = sortedOriginal[i] | ||
@@ -263,3 +263,3 @@ const newObj = sortedNew[i] | ||
| const largeInventoryOptionListData = [] | ||
| for (let i = 0 i < 1000 i++) { | ||
| for (let i = 0; i < 1000; i++) { | ||
| largeInventoryOptionListData.push({ | ||
@@ -283,3 +283,3 @@ optionnum: i, | ||
| // Add 100 tags to the product inventory row | ||
| for (let i = 0 i < 100 i++) { | ||
| for (let i = 0; i < 100; i++) { | ||
| largeProductInventoryRow.tags.push({ | ||
@@ -286,0 +286,0 @@ label: `Option${i}`, |
137299
0.19%3
-25%3089
0.42%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed