@@ -138,7 +138,6 @@ if (!fs.existsSync(dbPathLibrary)) {
138
138
}
139
139
console . log ( 'Conexión exitosa a la base de datos.' ) ;
140
140
141
- // Define aquí tus comandos SQL para crear tablas
142
141
const createTableSql = `CREATE TABLE "roms" (
143
142
"id" INTEGER,
144
143
"file_name" TEXT,
@@ -152,7 +151,7 @@ if (!fs.existsSync(dbPathLibrary)) {
152
151
"favourite" INTEGER DEFAULT 0,
153
152
PRIMARY KEY("id" AUTOINCREMENT),
154
153
UNIQUE("file_name")
155
- )` ; // Asegúrate de reemplazar esto con tu SQL para crear tablas
154
+ )` ;
156
155
db . run ( createTableSql , ( err ) => {
157
156
if ( err ) {
158
157
console . error ( err . message ) ;
@@ -590,46 +589,49 @@ const insertROM = (
590
589
// db.all(query, [`%${romNameForSearch}%`, platform], (err, rows) => {
591
590
db . all ( query , [ `%${ romNameForSearch } %` , platform ] , ( err , rows ) => {
592
591
const results = rows ;
593
-
592
+ const imageData = {
593
+ gameFile,
594
+ romNameTrimmed,
595
+ folderName,
596
+ platform,
597
+ gameFilePath,
598
+ } ;
594
599
if ( results . length > 0 ) {
595
- const insertQuery = `
596
- INSERT OR REPLACE INTO roms (file_name, name, system, platform, path, databaseID)
597
- VALUES (?, ?, ?, ?, ?, ?)
598
- ` ;
599
- const imageData = {
600
- gameFile,
601
- romNameTrimmed,
602
- folderName,
603
- platform,
604
- gameFilePath,
605
- } ;
606
600
results . forEach ( ( result ) => {
607
601
imageData . databaseID = result . DatabaseID ;
608
602
} ) ;
609
- // console.log({ imageData });
610
- dbLibrary . run (
611
- insertQuery ,
612
- [
613
- imageData . gameFile ,
614
- imageData . romNameTrimmed ,
615
- imageData . folderName ,
616
- imageData . platform ,
617
- imageData . gameFilePath ,
618
- imageData . databaseID ,
619
- ] ,
620
- function ( err ) {
603
+ } else {
604
+ imageData . databaseID = 0 ;
605
+ }
606
+
607
+ const insertQuery = `
608
+ INSERT OR REPLACE INTO roms (file_name, name, system, platform, path, databaseID)
609
+ VALUES (?, ?, ?, ?, ?, ?)
610
+ ` ;
611
+
612
+ // console.log({ imageData });
613
+ dbLibrary . run (
614
+ insertQuery ,
615
+ [
616
+ imageData . gameFile ,
617
+ imageData . romNameTrimmed ,
618
+ imageData . folderName ,
619
+ imageData . platform ,
620
+ imageData . gameFilePath ,
621
+ imageData . databaseID ,
622
+ ] ,
623
+ function ( err ) {
624
+ if ( err ) {
625
+ return console . error ( 'Error al insertar datos:' , err . message ) ;
626
+ }
627
+ fs . writeFile ( fileCachePath , '' , ( err ) => {
621
628
if ( err ) {
622
- return console . error ( 'Error al insertar datos :' , err . message ) ;
629
+ console . error ( 'Error writing the file :' , err ) ;
623
630
}
624
- fs . writeFile ( fileCachePath , '' , ( err ) => {
625
- if ( err ) {
626
- console . error ( 'Error writing the file:' , err ) ;
627
- }
628
- } ) ;
629
- } ,
630
- ) ;
631
- dbLibrary . close ( ) ;
632
- }
631
+ } ) ;
632
+ } ,
633
+ ) ;
634
+ dbLibrary . close ( ) ;
633
635
} ) ;
634
636
} ;
635
637
0 commit comments