@isoftdata/file-service
Advanced tools
| import { Connection, PoolConnection } from "mysql"; | ||
| export declare const handleQuery: <T = any>(options: { | ||
| connection: Connection | PoolConnection; | ||
| sql: string; | ||
| values: any[]; | ||
| }) => Promise<T>; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.handleQuery = void 0; | ||
| const handleQuery = (options) => new Promise((resolve, reject) => { | ||
| options.connection.query(options.sql, options.values, (err, rows) => { | ||
| if (err) | ||
| reject(err); | ||
| else | ||
| resolve(rows); | ||
| }); | ||
| }); | ||
| exports.handleQuery = handleQuery; |
@@ -33,3 +33,3 @@ import { transformImage } from '../utilities/transform-image.js'; | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
| const resultArray = await buildResultArray(fileEntities, maxHeight, maxWidth, fileRepo, sharpOptions); | ||
| const resultArray = await buildResultArray(fileEntities, maxHeight, maxWidth, fileRepo, connection, sharpOptions); | ||
| return res.send(resultArray); | ||
@@ -36,0 +36,0 @@ } |
@@ -6,2 +6,3 @@ import fileUpload from 'express-fileupload'; | ||
| import { UploadResult } from '../app/types.js'; | ||
| import { DatabaseConnectionInterface, DatabasePoolConnectionInterface } from '@isoftdata/utility-db'; | ||
| export interface SaveFileOptions { | ||
@@ -21,5 +22,5 @@ fileEntity: FileEntity; | ||
| export declare const buildFileEntity: (e: FileEntity, buffer: Buffer) => FileEntity; | ||
| export declare const buildResultArray: (fileEntities: FileEntity[], maxHeight: number, maxWidth: number, fileRepo: FileRepo, sharpOptions?: object) => Promise<UploadResult[]>; | ||
| export declare const buildResultArray: (fileEntities: FileEntity[], maxHeight: number, maxWidth: number, fileRepo: FileRepo, connection: DatabaseConnectionInterface | DatabasePoolConnectionInterface, sharpOptions?: object) => Promise<UploadResult[]>; | ||
| export declare const resizeImage: (input: SaveFileOptions) => Promise<FileEntity>; | ||
| export declare const renameFile: (input: SaveFileOptions) => string; | ||
| export declare const saveFileChunk: (fileRepo: FileRepo, input: SaveFileOptions) => Promise<number>; |
+12
-3
@@ -43,3 +43,3 @@ import sharp from 'sharp'; | ||
| }; | ||
| export const buildResultArray = async (fileEntities, maxHeight, maxWidth, fileRepo, sharpOptions) => { | ||
| export const buildResultArray = async (fileEntities, maxHeight, maxWidth, fileRepo, connection, sharpOptions) => { | ||
| const resultArray = []; | ||
@@ -57,4 +57,13 @@ for (const e of fileEntities) { | ||
| } | ||
| // upload the file and get an id | ||
| const id = await fileRepo.insert(fileEntity); | ||
| // upload the file and get an id, atomically | ||
| await connection.startTransaction(); | ||
| let id; | ||
| try { | ||
| id = await fileRepo.insert(fileEntity); | ||
| await connection.commitTransaction(); | ||
| } | ||
| catch (error) { | ||
| await connection.rollbackTransaction(); | ||
| throw error; | ||
| } | ||
| resultArray.push({ | ||
@@ -61,0 +70,0 @@ id, |
+1
-1
| { | ||
| "name": "@isoftdata/file-service", | ||
| "version": "7.0.2", | ||
| "version": "7.0.3", | ||
| "description": "A generic files service for any ISoft platform.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
38477
2.4%26
8.33%747
3.89%