-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sql.ts): add drop table functionality.
- Loading branch information
1 parent
87cd851
commit 1071f6e
Showing
5 changed files
with
110 additions
and
123 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
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 |
---|---|---|
@@ -1,16 +1 @@ | ||
import { excelToPostgresDb } from './sql'; | ||
|
||
excelToPostgresDb( | ||
{ | ||
host: 'localhost', | ||
user: 'postgres', | ||
password: 'postgres', | ||
port: 5432, | ||
database: 'test', | ||
}, | ||
'/Users/jim/Documents/workspace/multi-sport-draft-aid/server/data/baseball.xlsx', | ||
{ | ||
createDatabase: true, | ||
createTables: true, | ||
} | ||
).then((t) => console.log(t)); | ||
export { excelToPostgresDb } from './sql'; |
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 |
---|---|---|
@@ -1,60 +1,67 @@ | ||
import { | ||
createDatabase, | ||
createTable, | ||
handlePrimaryKey, | ||
insert, | ||
PrimaryKeyOptions, | ||
} from "../sql"; | ||
import { etlProcesses, sqlInfo, sqlResults } from "./test-data"; | ||
createDatabase, | ||
createTable, | ||
dropTable, | ||
handlePrimaryKey, | ||
insert, | ||
PrimaryKeyOptions, | ||
} from '../sql'; | ||
import { etlProcesses, sqlInfo, sqlResults } from './test-data'; | ||
|
||
describe("SQL tests", () => { | ||
test("create database", () => { | ||
expect(createDatabase(sqlInfo.database)).toEqual(sqlResults.createDatabase); | ||
}); | ||
describe('SQL tests', () => { | ||
test('create database', () => { | ||
expect(createDatabase(sqlInfo.database)).toEqual( | ||
sqlResults.createDatabase | ||
); | ||
}); | ||
|
||
test("create table generate primary key", () => { | ||
expect( | ||
createTable( | ||
sqlInfo.tableName, | ||
etlProcesses.sheet_one_pk, | ||
PrimaryKeyOptions.GENERATE | ||
) | ||
).toEqual(sqlResults.createTableGeneratedPrimaryKey); | ||
}); | ||
test('create table generate primary key', () => { | ||
expect( | ||
createTable( | ||
sqlInfo.tableName, | ||
etlProcesses.sheet_one_pk, | ||
PrimaryKeyOptions.GENERATE | ||
) | ||
).toEqual(sqlResults.createTableGeneratedPrimaryKey); | ||
}); | ||
|
||
test("create table one existing primary key", () => { | ||
expect( | ||
createTable( | ||
sqlInfo.tableName, | ||
etlProcesses.sheet_one_pk, | ||
PrimaryKeyOptions.USE_EXISTING | ||
) | ||
).toEqual(sqlResults.createTableOnePrimaryKey); | ||
}); | ||
test('create table one existing primary key', () => { | ||
expect( | ||
createTable( | ||
sqlInfo.tableName, | ||
etlProcesses.sheet_one_pk, | ||
PrimaryKeyOptions.USE_EXISTING | ||
) | ||
).toEqual(sqlResults.createTableOnePrimaryKey); | ||
}); | ||
|
||
test("create table multiple existing primary keys", () => { | ||
expect( | ||
createTable( | ||
sqlInfo.tableName, | ||
etlProcesses.sheet_multiple_pk, | ||
PrimaryKeyOptions.USE_EXISTING | ||
) | ||
).toEqual(sqlResults.createTableMultiplePrimaryKeys); | ||
}); | ||
test('drop table', () => { | ||
expect(dropTable(sqlInfo.tableName)).toEqual(sqlResults.dropTable); | ||
}); | ||
|
||
test("insert", () => { | ||
expect(insert(sqlInfo.tableName, [etlProcesses.sheet_one_pk])).toEqual( | ||
sqlResults.insert | ||
); | ||
}); | ||
test('create table multiple existing primary keys', () => { | ||
expect( | ||
createTable( | ||
sqlInfo.tableName, | ||
etlProcesses.sheet_multiple_pk, | ||
PrimaryKeyOptions.USE_EXISTING | ||
) | ||
).toEqual(sqlResults.createTableMultiplePrimaryKeys); | ||
}); | ||
|
||
test("handle primary key options", () => { | ||
expect(handlePrimaryKey({ generatePrimaryKey: true })).toEqual( | ||
PrimaryKeyOptions.GENERATE | ||
); | ||
expect(handlePrimaryKey({ useExistingPrimaryKeys: true })).toEqual( | ||
PrimaryKeyOptions.USE_EXISTING | ||
); | ||
expect(handlePrimaryKey({})).toEqual(PrimaryKeyOptions.NO_PRIMARY_KEY); | ||
}); | ||
test('insert', () => { | ||
expect(insert(sqlInfo.tableName, [etlProcesses.sheet_one_pk])).toEqual( | ||
sqlResults.insert | ||
); | ||
}); | ||
|
||
test('handle primary key options', () => { | ||
expect(handlePrimaryKey({ generatePrimaryKey: true })).toEqual( | ||
PrimaryKeyOptions.GENERATE | ||
); | ||
expect(handlePrimaryKey({ useExistingPrimaryKeys: true })).toEqual( | ||
PrimaryKeyOptions.USE_EXISTING | ||
); | ||
expect(handlePrimaryKey({})).toEqual(PrimaryKeyOptions.NO_PRIMARY_KEY); | ||
}); | ||
}); |
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