csv-sql-engine 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/csv/csv-file.js +10 -8
- package/dist/engine/define-ast-handler.d.ts +1 -1
- package/dist/engine/handlers/row-delete.handler.js +2 -2
- package/dist/engine/handlers/row-insert.handler.js +1 -1
- package/dist/engine/handlers/row-select.handler.js +2 -2
- package/dist/engine/handlers/row-update.handler.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
- /package/dist/{engine → util}/sort-values.d.ts +0 -0
- /package/dist/{engine → util}/sort-values.js +0 -0
- /package/dist/{engine → util}/where-matcher.d.ts +0 -0
- /package/dist/{engine → util}/where-matcher.js +0 -0
package/dist/csv/csv-file.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { assertWrap, check } from '@augment-vir/assert';
|
|
1
2
|
import { addSuffix, awaitedForEach, removeSuffix } from '@augment-vir/common';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
3
3
|
import { appendFile, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
5
|
import { CsvFileMissingHeadersError } from '../errors/csv.error.js';
|
|
@@ -26,6 +26,7 @@ export async function appendCsvRows(valueMatrix, csvFilePath) {
|
|
|
26
26
|
* @category CSV
|
|
27
27
|
*/
|
|
28
28
|
export async function appendCsvRow(row, csvFilePath) {
|
|
29
|
+
await mkdir(dirname(csvFilePath), { recursive: true });
|
|
29
30
|
await appendFile(csvFilePath, convertRowToCsv(row) + '\n');
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
@@ -34,10 +35,15 @@ export async function appendCsvRow(row, csvFilePath) {
|
|
|
34
35
|
* @category CSV
|
|
35
36
|
*/
|
|
36
37
|
export function nameCsvTableFile({ csvDirPath, tableName, }) {
|
|
37
|
-
const
|
|
38
|
+
const tableNameSplit = tableName.split('.').filter(check.isTruthy);
|
|
39
|
+
const databaseName = assertWrap.isTruthy((tableNameSplit.length > 1 ? tableNameSplit[0] || '' : 'main').replaceAll(/[./\\]/g, ''), 'No database name found.');
|
|
40
|
+
const sanitizedTableName = assertWrap.isTruthy(removeSuffix({
|
|
41
|
+
value: tableNameSplit.length > 1 ? tableNameSplit[1] || '' : tableName,
|
|
42
|
+
suffix: csvExtension,
|
|
43
|
+
}).replaceAll(/[./\\]/g, ''), 'No table name found.');
|
|
38
44
|
const newCsvFileName = addSuffix({ value: sanitizedTableName, suffix: csvExtension });
|
|
39
45
|
return {
|
|
40
|
-
tableFilePath: join(csvDirPath, newCsvFileName),
|
|
46
|
+
tableFilePath: join(csvDirPath, databaseName, newCsvFileName),
|
|
41
47
|
sanitizedTableName,
|
|
42
48
|
};
|
|
43
49
|
}
|
|
@@ -57,12 +63,8 @@ export async function readCsvFile(filePath) {
|
|
|
57
63
|
* @category CSV
|
|
58
64
|
*/
|
|
59
65
|
export async function writeCsvFile(filePath, contents) {
|
|
60
|
-
if (!existsSync(filePath)) {
|
|
61
|
-
await mkdir(dirname(filePath), {
|
|
62
|
-
recursive: true,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
66
|
const fileContents = convertRowsToCsv(contents);
|
|
67
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
66
68
|
await writeFile(filePath, fileContents);
|
|
67
69
|
}
|
|
68
70
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MaybePromise } from '@augment-vir/common';
|
|
2
|
+
import { type SortValuesOutput } from '../util/sort-values.js';
|
|
2
3
|
import { type AstHandlerParams } from './params.js';
|
|
3
|
-
import { type SortValuesOutput } from './sort-values.js';
|
|
4
4
|
/**
|
|
5
5
|
* Output from a handler that handled a SQL query.
|
|
6
6
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { nameCsvTableFile, readCsvFile, readCsvHeaders, writeCsvFile } from '../../csv/csv-file.js';
|
|
2
2
|
import { getAstType } from '../../util/ast-node.js';
|
|
3
|
+
import { sortValues } from '../../util/sort-values.js';
|
|
4
|
+
import { findWhereMatches } from '../../util/where-matcher.js';
|
|
3
5
|
import { defineAstHandler } from '../define-ast-handler.js';
|
|
4
|
-
import { sortValues } from '../sort-values.js';
|
|
5
|
-
import { findWhereMatches } from '../where-matcher.js';
|
|
6
6
|
/**
|
|
7
7
|
* Handles deleting rows.
|
|
8
8
|
*
|
|
@@ -4,8 +4,8 @@ import { existsSync } from 'node:fs';
|
|
|
4
4
|
import { appendCsvRow, nameCsvTableFile, readCsvFile, readCsvHeaders } from '../../csv/csv-file.js';
|
|
5
5
|
import { CsvTableDoesNotExistError } from '../../errors/csv.error.js';
|
|
6
6
|
import { SqlUnsupportedOperationError } from '../../errors/sql.error.js';
|
|
7
|
+
import { sortValues } from '../../util/sort-values.js';
|
|
7
8
|
import { defineAstHandler } from '../define-ast-handler.js';
|
|
8
|
-
import { sortValues } from '../sort-values.js';
|
|
9
9
|
/**
|
|
10
10
|
* Handles inserting rows.
|
|
11
11
|
*
|
|
@@ -3,9 +3,9 @@ import { filterMap } from '@augment-vir/common';
|
|
|
3
3
|
import { nameCsvTableFile, readCsvFile, readCsvHeaders } from '../../csv/csv-file.js';
|
|
4
4
|
import { SqlUnsupportedOperationError } from '../../errors/sql.error.js';
|
|
5
5
|
import { getAstType } from '../../util/ast-node.js';
|
|
6
|
+
import { sortValues } from '../../util/sort-values.js';
|
|
7
|
+
import { findWhereMatches } from '../../util/where-matcher.js';
|
|
6
8
|
import { defineAstHandler } from '../define-ast-handler.js';
|
|
7
|
-
import { sortValues } from '../sort-values.js';
|
|
8
|
-
import { findWhereMatches } from '../where-matcher.js';
|
|
9
9
|
/**
|
|
10
10
|
* Handles SQL selection.
|
|
11
11
|
*
|
|
@@ -2,9 +2,9 @@ import { assertWrap } from '@augment-vir/assert';
|
|
|
2
2
|
import { createCsvHeaderMaps, nameCsvTableFile, readCsvFile, readCsvHeaders, writeCsvFile, } from '../../csv/csv-file.js';
|
|
3
3
|
import { CsvColumnDoesNotExistError } from '../../errors/csv.error.js';
|
|
4
4
|
import { getAstType } from '../../util/ast-node.js';
|
|
5
|
+
import { sortValues } from '../../util/sort-values.js';
|
|
6
|
+
import { findWhereMatches } from '../../util/where-matcher.js';
|
|
5
7
|
import { defineAstHandler } from '../define-ast-handler.js';
|
|
6
|
-
import { sortValues } from '../sort-values.js';
|
|
7
|
-
import { findWhereMatches } from '../where-matcher.js';
|
|
8
8
|
/**
|
|
9
9
|
* Handles updating rows.
|
|
10
10
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ export * from './engine/handlers/table-alter.handler.js';
|
|
|
11
11
|
export * from './engine/handlers/table-create.handler.js';
|
|
12
12
|
export * from './engine/handlers/table-drop.handler.js';
|
|
13
13
|
export * from './engine/params.js';
|
|
14
|
-
export * from './engine/sort-values.js';
|
|
15
|
-
export * from './engine/where-matcher.js';
|
|
16
14
|
export * from './errors/csv-sql-engine.error.js';
|
|
17
15
|
export * from './errors/csv.error.js';
|
|
18
16
|
export * from './errors/sql.error.js';
|
|
17
|
+
export * from './util/sort-values.js';
|
|
18
|
+
export * from './util/where-matcher.js';
|
package/dist/index.js
CHANGED
|
@@ -11,8 +11,8 @@ export * from './engine/handlers/table-alter.handler.js';
|
|
|
11
11
|
export * from './engine/handlers/table-create.handler.js';
|
|
12
12
|
export * from './engine/handlers/table-drop.handler.js';
|
|
13
13
|
export * from './engine/params.js';
|
|
14
|
-
export * from './engine/sort-values.js';
|
|
15
|
-
export * from './engine/where-matcher.js';
|
|
16
14
|
export * from './errors/csv-sql-engine.error.js';
|
|
17
15
|
export * from './errors/csv.error.js';
|
|
18
16
|
export * from './errors/sql.error.js';
|
|
17
|
+
export * from './util/sort-values.js';
|
|
18
|
+
export * from './util/where-matcher.js';
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|