-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a225899
commit 8866be1
Showing
16 changed files
with
290 additions
and
55 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import mySQLDetector from "./mySqlDetector.js"; | ||
import sqliteDetector from "./sqliteDetector.js"; | ||
import postgresDetector from "./postgresDetector.js"; | ||
|
||
export { mySQLDetector, sqliteDetector }; | ||
export { mySQLDetector, sqliteDetector, postgresDetector }; |
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,37 @@ | ||
const getDatabaseColumns = async (knex, schema) => { | ||
const { rows } = await knex.raw( | ||
` | ||
SELECT C.*, TC.constraint_type = 'PRIMARY KEY' AS is_primary | ||
FROM information_schema.columns C | ||
LEFT JOIN information_schema.key_column_usage KCU ON KCU.table_name = C.table_name AND KCU.column_name = C.column_name | ||
LEFT JOIN information_schema.table_constraints TC ON TC.constraint_name = KCU.constraint_name | ||
WHERE C.table_schema = ? | ||
`, | ||
[schema] | ||
); | ||
return rows; | ||
}; | ||
|
||
export default async ({ knex, schema }) => { | ||
const databaseColumns = await getDatabaseColumns(knex, schema); | ||
|
||
if (!databaseColumns) { | ||
throw new Error("Auto-column detection is failed on PostgreSQL!"); | ||
} | ||
|
||
return databaseColumns.map((i) => { | ||
return { | ||
name: i.column_name, | ||
tableName: i.table_name, | ||
isNullable: i.is_nullable === "YES", | ||
dataType: i.data_type, | ||
defaultValue: i.column_default, | ||
maxLength: i.character_maximum_length, | ||
numericPrecision: i.numeric_precision, | ||
numericScale: i.numeric_scale, | ||
isPrimary: i.is_primary ? i.is_primary : false, | ||
isAutoIncrement: | ||
i.column_default && i.column_default.indexOf("nextval") > -1, | ||
}; | ||
}); | ||
}; |
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,11 @@ | ||
version: "3.9" | ||
|
||
services: | ||
database: | ||
image: postgres:13 | ||
environment: | ||
POSTGRES_DB: axeapi | ||
POSTGRES_USER: axeapi | ||
POSTGRES_PASSWORD: 123456 | ||
ports: | ||
- "5433:5432" |
Oops, something went wrong.