feat: add MySqlOperationService for archive extraction, query execution, and database management
This commit is contained in:
@@ -2,6 +2,7 @@ import fs from 'fs'
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { spawn } from 'child_process'
|
import { spawn } from 'child_process'
|
||||||
import decompress from 'decompress'
|
import decompress from 'decompress'
|
||||||
|
import zlib from 'zlib'
|
||||||
|
|
||||||
export interface MySqlConfig {
|
export interface MySqlConfig {
|
||||||
binPath: string
|
binPath: string
|
||||||
@@ -17,6 +18,26 @@ export class MySqlOperationService {
|
|||||||
fs.mkdirSync(targetDir, { recursive: true })
|
fs.mkdirSync(targetDir, { recursive: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const lowerPath = archivePath.toLowerCase()
|
||||||
|
if (lowerPath.endsWith('.gz') && !lowerPath.endsWith('.tar.gz')) {
|
||||||
|
// Handle single-file gzip compression like .sql.gz
|
||||||
|
const baseName = path.basename(archivePath, '.gz')
|
||||||
|
const outPath = path.join(targetDir, baseName.endsWith('.sql') ? baseName : `${baseName}.sql`)
|
||||||
|
|
||||||
|
const source = fs.createReadStream(archivePath)
|
||||||
|
const destination = fs.createWriteStream(outPath)
|
||||||
|
const unzip = zlib.createUnzip()
|
||||||
|
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
source.pipe(unzip).pipe(destination)
|
||||||
|
.on('finish', () => resolve(true))
|
||||||
|
.on('error', reject)
|
||||||
|
})
|
||||||
|
|
||||||
|
return [outPath]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process standard archives (tar, zip, tar.gz)
|
||||||
await decompress(archivePath, targetDir)
|
await decompress(archivePath, targetDir)
|
||||||
|
|
||||||
// Find all .sql files in the extracted directory
|
// Find all .sql files in the extracted directory
|
||||||
|
|||||||
Reference in New Issue
Block a user