@ -6,11 +6,11 @@ import { runMigrations } from "../db-sql/migration"; 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					import  type  {  DatabaseService ,  QueryExecResult  }  from  "../interfaces/database" ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					import  {  logger  }  from  "@/utils/logger" ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					interface  QueuedOperation < T  =  unknown >   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					interface  QueuedOperation  {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  type :  "run"  |  "query"  |  "getOneRow"  |  "getAll" ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  sql : string ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  params : unknown [ ] ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  resolve :  ( value : T )  = >  void ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  resolve :  ( value : unknown )  = >  void ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  reject :  ( reason : unknown )  = >  void ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					}  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					
 
				
			 
			
		
	
	
		
			
				
					
						
						
						
							
								 
							 
						
					 
				
				 
				
					@ -22,12 +22,12 @@ interface AbsurdSqlDatabase { 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  )  = >  Promise < {  changes : number ;  lastId? : number  } > ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					}  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					class  AbsurdSqlDatabaseService < T >   implements  DatabaseService  {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					class  AbsurdSqlDatabaseService  implements  DatabaseService  {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  private  static  instance : AbsurdSqlDatabaseService  |  null  =  null ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  private  db : AbsurdSqlDatabase  |  null ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  private  initialized : boolean ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  private  initializationPromise : Promise < void >  |  null  =  null ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  private  operationQueue : Array < QueuedOperation < T > >  =  [ ] ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  private  operationQueue : Array < QueuedOperation >  =  [ ] ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  private  isProcessingQueue : boolean  =  false ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  private  constructor ( )  {  
				
			 
			
		
	
	
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
				
				 
				
					@ -123,9 +123,7 @@ class AbsurdSqlDatabaseService<T> implements DatabaseService { 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					      if  ( ! operation )  continue ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					      try  {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					        let  result ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					        let  queryResult ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					        let  allResult ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					        let  result : unknown ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					        switch  ( operation . type )  {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					          case  "run" :  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					            result  =  await  this . db . run ( operation . sql ,  operation . params ) ;  
				
			 
			
		
	
	
		
			
				
					
						
						
						
							
								 
							 
						
					 
				
				 
				
					@ -134,11 +132,11 @@ class AbsurdSqlDatabaseService<T> implements DatabaseService { 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					            result  =  await  this . db . exec ( operation . sql ,  operation . params ) ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					            break ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					          case  "getOneRow" :  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					            queryResult  =  await  this . db . exec ( operation . sql ,  operation . params ) ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					            const  queryResult  =  await  this . db . exec ( operation . sql ,  operation . params ) ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					            result  =  queryResult [ 0 ] ? . values [ 0 ] ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					            break ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					          case  "getAll" :  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					            allResult  =  await  this . db . exec ( operation . sql ,  operation . params ) ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					            const  allResult  =  await  this . db . exec ( operation . sql ,  operation . params ) ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					            result  =  allResult [ 0 ] ? . values  ||  [ ] ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					            break ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					        }  
				
			 
			
		
	
	
		
			
				
					
						
						
						
							
								 
							 
						
					 
				
				 
				
					@ -151,17 +149,17 @@ class AbsurdSqlDatabaseService<T> implements DatabaseService { 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					    this . isProcessingQueue  =  false ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  }  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  private  async  queueOperation < T > (  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					    type :  QueuedOperation < T > [ "type" ] ,  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  private  async  queueOperation < R > (  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					    type :  QueuedOperation [ "type" ] ,  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					    sql : string ,  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					    params : unknown [ ]  =  [ ] ,  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  ) :  Promise < T >  {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					    return  new  Promise < T > ( ( resolve ,  reject )  = >  {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					      const  operation : QueuedOperation < T >   =  {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					  ) :  Promise < R >  {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					    return  new  Promise < R > ( ( resolve ,  reject )  = >  {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					      const  operation : QueuedOperation  =  {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					        type ,  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					        sql ,  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					        params ,  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					        resolve ,  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					        resolve :  ( value : unknown )  = >  resolve ( value  as  R ) ,  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					        reject ,  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					      } ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					      this . operationQueue . push ( operation ) ;