| 72 | } |
| 73 | |
| 74 | export default class oracleDB implements SchemaInspector { |
| 75 | knex: Knex; |
| 76 | |
| 77 | constructor(knex: Knex) { |
| 78 | this.knex = knex; |
| 79 | } |
| 80 | |
| 81 | // Tables |
| 82 | // =============================================================================================== |
| 83 | |
| 84 | async overview(): Promise<SchemaOverview> { |
| 85 | type RawColumn = { |
| 86 | table_name: string; |
| 87 | column_name: string; |
| 88 | default_value: string; |
| 89 | is_nullable: string; |
| 90 | is_generated: string; |
| 91 | data_type: string; |
| 92 | numeric_precision: number | null; |
| 93 | numeric_scale: number | null; |
| 94 | column_key: string; |
| 95 | max_length: number | null; |
| 96 | }; |
| 97 | |
| 98 | /** |
| 99 | * NOTICE: This query is optimized for speed. Please keep this in mind. |
| 100 | */ |
| 101 | const columns = await this.knex.raw<RawColumn[]>(` |
| 102 | WITH "uc" AS ( |
| 103 | SELECT /*+ MATERIALIZE */ |
| 104 | "uc"."TABLE_NAME", |
| 105 | "ucc"."COLUMN_NAME", |
| 106 | "uc"."CONSTRAINT_TYPE", |
| 107 | COUNT(*) OVER( |
| 108 | PARTITION BY |
| 109 | "uc"."CONSTRAINT_NAME" |
| 110 | ) "CONSTRAINT_COUNT" |
| 111 | FROM "USER_CONSTRAINTS" "uc" |
| 112 | INNER JOIN "USER_CONS_COLUMNS" "ucc" |
| 113 | ON "uc"."CONSTRAINT_NAME" = "ucc"."CONSTRAINT_NAME" |
| 114 | AND "uc"."CONSTRAINT_TYPE" = 'P' |
| 115 | ) |
| 116 | SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.4') */ |
| 117 | "c"."TABLE_NAME" "table_name", |
| 118 | "c"."COLUMN_NAME" "column_name", |
| 119 | "c"."DATA_DEFAULT" "default_value", |
| 120 | "c"."NULLABLE" "is_nullable", |
| 121 | "c"."DATA_TYPE" "data_type", |
| 122 | "c"."DATA_PRECISION" "numeric_precision", |
| 123 | "c"."DATA_SCALE" "numeric_scale", |
| 124 | "ct"."CONSTRAINT_TYPE" "column_key", |
| 125 | "c"."CHAR_LENGTH" "max_length", |
| 126 | "c"."VIRTUAL_COLUMN" "is_generated" |
| 127 | FROM "USER_TAB_COLS" "c" |
| 128 | LEFT JOIN "uc" "ct" |
| 129 | ON "c"."TABLE_NAME" = "ct"."TABLE_NAME" |
| 130 | AND "c"."COLUMN_NAME" = "ct"."COLUMN_NAME" |
| 131 | AND "ct"."CONSTRAINT_COUNT" = 1 |
nothing calls this directly
no outgoing calls
no test coverage detected