@@ -45,7 +45,7 @@ export class SQLiteManager {
4545 }
4646 }
4747
48- queryBuilder ( op ?: AT , column ?: SQLiteManagerColumn , newColumn ?: string ) : string {
48+ queryBuilder ( op ?: AT | string , column ?: SQLiteManagerColumn , newColumn ?: string ) : string {
4949 let query = ''
5050
5151 if ( this . table . columns ) {
@@ -62,6 +62,7 @@ export class SQLiteManager {
6262 query += ');'
6363 } else {
6464 if ( typeof op != 'undefined' && column ) {
65+ let rand : string
6566 switch ( op ) {
6667 case AT . RENAME_TABLE :
6768 this . query += 'ALTER TABLE "' + this . table . name + '" RENAME TO "' + column . name + '";\n'
@@ -74,6 +75,19 @@ export class SQLiteManager {
7475 break
7576 case AT . RENAME_COLUMN :
7677 if ( newColumn ) this . query += 'ALTER TABLE "' + this . table . name + '" RENAME COLUMN "' + column . name + '" TO "' + newColumn + '";\n'
78+ break
79+ default :
80+ rand = Math . floor ( Math . random ( ) * 1000000000000 ) . toString ( )
81+ this . query += '\n\nPRAGMA foreign_keys = OFF;\n'
82+ this . query += 'BEGIN TRANSACTION;\n'
83+ this . query += 'ALTER TABLE "' + this . table . name + '" RENAME TO sqlitemanager_temp_table_' + rand + ';\n'
84+ this . create = true
85+ this . query += this . queryBuilder ( )
86+ this . create = false
87+ this . query += '\nDROP TABLE sqlitemanager_temp_table_' + rand + ';\n'
88+ this . query += 'COMMIT;\n'
89+ this . query += 'PRAGMA foreign_keys = ON;\n'
90+
7791 break
7892 }
7993 }
@@ -183,7 +197,7 @@ export class SQLiteManager {
183197 this . table . columns [ i ] . type = type
184198 }
185199
186- return this . queryBuilder ( )
200+ return this . queryBuilder ( '' , { } as SQLiteManagerColumn )
187201 }
188202
189203 changeColumnConstraints ( name : string , constraints : SQLiteManagerConstraints ) : string {
@@ -193,7 +207,7 @@ export class SQLiteManager {
193207 this . table . columns [ i ] . constraints = constraints
194208 }
195209
196- return this . queryBuilder ( )
210+ return this . queryBuilder ( '' , { } as SQLiteManagerColumn )
197211 }
198212
199213 private findColumn ( name : string ) : number | undefined {
0 commit comments