@@ -47,8 +47,14 @@ export class SQLiteManager {
4747 }
4848
4949 /** Pass to this method the result of this query: SELECT sql FROM sqlite_schema WHERE tbl_name='X'; where X is the name of the table you're using */
50- sqlite_schema ( sql : string [ ] ) : void {
51- this . sql = sql
50+ sqlite_schema ( sql ?: string [ ] ) : void {
51+ if ( sql ) {
52+ this . sql = sql
53+ } else {
54+ if ( ! this . create ) {
55+ throw new Error ( 'Alter table needs SELECT sql FROM sqlite_schema WHERE tbl_name=X; as sql' )
56+ }
57+ }
5258 }
5359
5460 /** If changing name in altertable you need to manually call the queryBuilder() */
@@ -133,18 +139,17 @@ export class SQLiteManager {
133139 this . query += 'DROP TABLE "' + oldname + '";\n'
134140 this . query += 'ALTER TABLE "' + this . table . name + '" RENAME TO "' + oldname + '";\n'
135141 this . table . name = oldname
136- this . query += 'CREATE INDEX '
137142
138143 if ( this . sql ) {
139144 if ( op == 'DROP_COLUMN' && column ) {
140145 this . sql . forEach ( element => {
141146 if ( ! element . includes ( column . name ) ) {
142- query += element + '\n'
147+ this . query += element + '\n'
143148 }
144149 } )
145150 } else {
146151 this . sql . forEach ( element => {
147- query += element + '\n'
152+ this . query += element + '\n'
148153 } )
149154 }
150155 }
@@ -235,7 +240,7 @@ export class SQLiteManager {
235240 * column: the SQLiteManagerColumn you want to add to the table
236241 * sql[]: SELECT sql FROM sqlite_schema WHERE tbl_name='X'; where X is the name of the table you're using
237242 */
238- addColumn ( column : SQLiteManagerColumn , sql : string [ ] ) : string {
243+ addColumn ( column : SQLiteManagerColumn , sql ? : string [ ] ) : string {
239244 if ( this . table . columns ) {
240245 if ( typeof this . findColumn ( column . name ) == 'undefined' ) {
241246 this . table . columns . push ( column )
@@ -254,7 +259,7 @@ export class SQLiteManager {
254259 * name: name of the column you want to delete
255260 * sql[]: SELECT sql FROM sqlite_schema WHERE tbl_name='X'; where X is the name of the table you're using
256261 */
257- deleteColumn ( name : string , sql : string [ ] ) : string {
262+ deleteColumn ( name : string , sql ? : string [ ] ) : string {
258263 let query = ''
259264 const i = this . findColumn ( name )
260265
@@ -291,7 +296,7 @@ export class SQLiteManager {
291296 * type: the new type you want to give to the column
292297 * sql[]: SELECT sql FROM sqlite_schema WHERE tbl_name='X'; where X is the name of the table you're using
293298 */
294- changeColumnType ( name : string , type : SQLiteManagerType , sql : string [ ] ) : string {
299+ changeColumnType ( name : string , type : SQLiteManagerType , sql ? : string [ ] ) : string {
295300 return this . generalFun ( name , ( column : SQLiteManagerColumn ) => ( column . type = type ) , sql )
296301 }
297302
@@ -300,7 +305,7 @@ export class SQLiteManager {
300305 * constraits: edited constraints you get from getConstraints()
301306 * sql[]: SELECT sql FROM sqlite_schema WHERE tbl_name='X'; where X is the name of the table you're using
302307 */
303- changeColumnConstraints ( name : string , constraints : SQLiteManagerConstraints , sql : string [ ] ) : string {
308+ changeColumnConstraints ( name : string , constraints : SQLiteManagerConstraints , sql ? : string [ ] ) : string {
304309 return this . generalFun ( name , ( column : SQLiteManagerColumn ) => ( column . constraints = constraints ) , sql )
305310 }
306311
@@ -318,9 +323,7 @@ export class SQLiteManager {
318323 fun ( this . table . columns [ i ] )
319324 }
320325
321- if ( sql ) {
322- this . sqlite_schema ( sql )
323- }
326+ this . sqlite_schema ( sql )
324327
325328 return this . queryBuilder ( qb1 ? qb1 : '' , qb2 ? qb2 : ( { } as SQLiteManagerColumn ) )
326329 }
0 commit comments