-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add functions that take datasets as parameter instead of json. These functions can be used for example from front end. - Also move the inserter functions for clearance: "json-parser" does not indicate of any db insertions.
- Loading branch information
1 parent
1f7a3f6
commit 7346c92
Showing
8 changed files
with
71 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
test/hasura/timetables-data-inserter/generic/data-insert.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { timetablesDbConfig } from '@config'; | ||
import { closeDbConnection, createDbConnection } from '@util/db'; | ||
import { setupDb } from '@util/setup'; | ||
import { ConnectionConfig } from 'pg'; | ||
import { buildGenericTimetablesDataset } from './dataset'; | ||
import { parseGenericDatasetJson } from './json-parser'; | ||
import { createGenericTableData } from './table-data'; | ||
import { GenericTimetablesDatasetInput } from './types'; | ||
|
||
export const insertDatasetFromJson = async ( | ||
input: string, | ||
dbConfig: ConnectionConfig = timetablesDbConfig, | ||
) => { | ||
const result = parseGenericDatasetJson(input); | ||
const builtDataset = buildGenericTimetablesDataset(result); | ||
const dbConnection = createDbConnection(dbConfig); | ||
const tableData = createGenericTableData(builtDataset); | ||
await setupDb(dbConnection, tableData); | ||
closeDbConnection(dbConnection); | ||
return builtDataset; | ||
}; | ||
|
||
export const insertGenericDataset = async ( | ||
input: GenericTimetablesDatasetInput, | ||
dbConfig: ConnectionConfig = timetablesDbConfig, | ||
) => { | ||
const builtDataset = buildGenericTimetablesDataset(input); | ||
const tableData = createGenericTableData(builtDataset); | ||
const dbConnection = createDbConnection(dbConfig); | ||
await setupDb(dbConnection, tableData); | ||
closeDbConnection(dbConnection); | ||
return builtDataset; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { timetablesDbConfig } from '@config'; | ||
import { closeDbConnection, createDbConnection } from '@util/db'; | ||
import { setupDb } from '@util/setup'; | ||
import { ConnectionConfig } from 'pg'; | ||
import { buildHslTimetablesDataset } from './dataset'; | ||
import { parseHslDatasetJson } from './json-parser'; | ||
import { createHslTableData } from './table-data'; | ||
import { HslTimetablesDatasetInput } from './types'; | ||
|
||
export const insertDatasetFromJson = async ( | ||
input: string, | ||
dbConfig: ConnectionConfig = timetablesDbConfig, | ||
) => { | ||
const result = parseHslDatasetJson(input); | ||
const builtDataset = buildHslTimetablesDataset(result); | ||
const dbConnection = createDbConnection(dbConfig); | ||
const tableData = createHslTableData(builtDataset); | ||
await setupDb(dbConnection, tableData); | ||
closeDbConnection(dbConnection); | ||
return builtDataset; | ||
}; | ||
|
||
export const insertHslDataset = async ( | ||
input: HslTimetablesDatasetInput, | ||
dbConfig: ConnectionConfig = timetablesDbConfig, | ||
) => { | ||
const builtDataset = buildHslTimetablesDataset(input); | ||
const tableData = createHslTableData(builtDataset); | ||
const dbConnection = createDbConnection(dbConfig); | ||
await setupDb(dbConnection, tableData); | ||
closeDbConnection(dbConnection); | ||
return builtDataset; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters