File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -638,7 +638,10 @@ export class SqlDriver implements Driver {
638638 } ) ;
639639 }
640640 } else if ( this . config . client === 'sqlite3' ) {
641- const result = await this . knex . raw ( `PRAGMA foreign_key_list(${ tableName } )` ) ;
641+ // SQLite PRAGMA doesn't support parameter binding, so we need to ensure safe identifier
642+ // Table names in ObjectQL are validated and should be safe, but we add extra protection
643+ const safeTableName = tableName . replace ( / [ ^ a - z A - Z 0 - 9 _ ] / g, '' ) ;
644+ const result = await this . knex . raw ( `PRAGMA foreign_key_list(${ safeTableName } )` ) ;
642645
643646 for ( const row of result ) {
644647 foreignKeys . push ( {
@@ -689,7 +692,10 @@ export class SqlDriver implements Driver {
689692 primaryKeys . push ( row . column_name ) ;
690693 }
691694 } else if ( this . config . client === 'sqlite3' ) {
692- const result = await this . knex . raw ( `PRAGMA table_info(${ tableName } )` ) ;
695+ // SQLite PRAGMA doesn't support parameter binding, so we need to ensure safe identifier
696+ // Table names in ObjectQL are validated and should be safe, but we add extra protection
697+ const safeTableName = tableName . replace ( / [ ^ a - z A - Z 0 - 9 _ ] / g, '' ) ;
698+ const result = await this . knex . raw ( `PRAGMA table_info(${ safeTableName } )` ) ;
693699
694700 for ( const row of result ) {
695701 if ( row . pk === 1 ) {
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import { ObjectRepository } from './repository';
2121import { executeActionHelper , registerActionHelper , ActionEntry } from './action' ;
2222import { registerHookHelper , triggerHookHelper , HookEntry } from './hook' ;
2323import { registerObjectHelper , getConfigsHelper } from './object' ;
24+ import { convertIntrospectedSchemaToObjects } from './util' ;
2425
2526export class ObjectQL implements IObjectQL {
2627 public metadata : MetadataRegistry ;
@@ -183,9 +184,6 @@ export class ObjectQL implements IObjectQL {
183184 console . log ( `Introspecting database schema from datasource '${ datasourceName } '...` ) ;
184185 const introspectedSchema = await driver . introspectSchema ( ) ;
185186
186- // Import the conversion utility
187- const { convertIntrospectedSchemaToObjects } = await import ( './util' ) ;
188-
189187 // Convert introspected schema to ObjectQL objects
190188 const objects = convertIntrospectedSchemaToObjects ( introspectedSchema , options ) ;
191189
Original file line number Diff line number Diff line change @@ -123,13 +123,14 @@ export function convertIntrospectedSchemaToObjects(
123123 fieldConfig . unique = true ;
124124 }
125125
126+ // Add max length for text fields
126127 // Add max length for text fields
127128 if ( column . maxLength && ( fieldType === 'text' || fieldType === 'textarea' ) ) {
128129 fieldConfig . max_length = column . maxLength ;
129130 }
130131
131132 // Add default value
132- if ( column . defaultValue !== undefined && column . defaultValue !== null ) {
133+ if ( column . defaultValue != null ) {
133134 fieldConfig . defaultValue = column . defaultValue ;
134135 }
135136 }
You can’t perform that action at this time.
0 commit comments