xl1 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/ls1/index.js +2 -2
- package/package.json +1 -1
package/dist/ls1/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#! /usr/bin/env node
|
2
|
-
"use strict";var _chunkNEJSZOZXjs = require('../chunk-NEJSZOZX.js');var
|
2
|
+
"use strict";var _chunkNEJSZOZXjs = require('../chunk-NEJSZOZX.js');var y=_chunkNEJSZOZXjs.b.call(void 0, (j,T)=>{var $=_chunkNEJSZOZXjs.a.call(void 0, "sqlite3").verbose(),p=class{constructor(t){this.db=new $.Database(t,e=>{e&&console.error("Error opening database:",e)})}close(){return new Promise((t,e)=>{this.db.close(s=>{s?e(s):t()})})}debug(t,...e){t.debug&&console.log("[SQLite Debug]",...e)}generateCreateTableSql(t,e,s){if(!t||t.length===0)return null;let i=t[0],r=Object.keys(i).map((n,c)=>{let l="TEXT";return s&&n.toLocaleLowerCase()===s.toLocaleLowerCase()?`"${n}" ${l} PRIMARY KEY`:`"${n}" ${l}`});return`CREATE TABLE IF NOT EXISTS "${e}" (${r.join(", ")})`}generateUpsertSql(t,e,s){if(!t||t.length===0)return null;let i=Object.keys(t[0]),r=i.map(()=>"?").join(", "),a=i.slice(1).map(n=>`"${n}"=excluded."${n}"`).join(", ");return`INSERT INTO "${e}" (${i.map(n=>`"${n}"`).join(", ")})
|
3
3
|
VALUES (${r})
|
4
4
|
ON CONFLICT("${s}") DO UPDATE SET ${a}`}generateInsertSql(t,e){if(!t||t.length===0)return null;let s=Object.keys(t[0]),i=s.map(()=>"?").join(", ");return`INSERT INTO "${e}" (${s.map(r=>`"${r}"`).join(", ")})
|
5
5
|
VALUES (${i})`}generateUpdateSql(t,e,s){if(!t||t.length===0)return null;let r=Object.keys(t[0]).filter(a=>a.toLowerCase()!==s.toLowerCase()).map(a=>`"${a}"=?`).join(", ");return`UPDATE "${e}" SET ${r}
|
6
|
-
WHERE "${s}"=?`}async createTable(t,e,s,i){let r=this.generateCreateTableSql(t,e,s);if(!r)throw new Error("No data provided for table creation");return this.debug(i,"Creating table with SQL:",r),new Promise((a,n)=>{this.db.run(r,c=>{c?(this.debug(i,"Error creating table:",c),n(c)):(this.debug(i,"Table created successfully"),a())})})}async addIndex(t,e,s){let i=`CREATE INDEX IF NOT EXISTS idx_${t}_${e} ON "${t}" ("${e}")`;return this.debug(s,"Creating index with SQL:",i),new Promise((r,a)=>{this.db.run(i,n=>{n?(this.debug(s,"Error creating index:",n),a(n)):(this.debug(s,"Index created successfully"),r())})})}async tableExists(t,e){let s="SELECT name FROM sqlite_master WHERE type='table' AND name=?";return this.debug(e,"Checking table existence:",s,[t]),new Promise((i,r)=>{this.db.get(s,[t],(a,n)=>{a?(this.debug(e,"Error checking table existence:",a),r(a)):(this.debug(e,"Table exists:",!!n),i(!!n))})})}async alterTable(t,e,s){this.debug(s,"Checking columns for table:",e);let r=(await this.query(`PRAGMA table_info("${e}");`,[],s)).map(c=>c.name),n=Object.keys(t[0]).filter(c=>!r.includes(c));if(this.debug(s,"Columns to add:",n),n.length>0)for(let c of n){let l=`ALTER TABLE "${e}" ADD COLUMN "${c}" TEXT;`;this.debug(s,"Altering table with SQL:",l),await new Promise((d,h)=>{this.db.run(l,g=>{g?(this.debug(s,"Error altering table:",g),h(g)):(this.debug(s,`Column "${c}" added successfully`),d())})})}}async insert(t,e){if(!t||t.length===0)throw new Error("No data provided");let{tableName:s,primaryKey:i,isAlterTable:r}=e;this.debug(e,"Starting insert operation:",{tableName:s,primaryKey:i,isAlterTable:r});try{await this.tableExists(s,e)?r&&(this.debug(e,"Table exists, checking for alterations"),await this.alterTable(t,s,e)):(this.debug(e,"Table does not exist, creating new table"),await this.createTable(t,s,i,e));let n=this.generateInsertSql(t,s);return this.debug(e,"Generated insert SQL:",n),new Promise((c,l)=>{let d=this.db.prepare(n);this.db.serialize(()=>{this.debug(e,"Beginning transaction"),this.db.run("BEGIN TRANSACTION"),t.forEach((h,g)=>{let m=Object.values(h);this.debug(e,`Processing row ${g+1}/${t.length}:`),d.run(m)}),d.finalize(),this.db.run("COMMIT",h=>{h?(this.debug(e,"Error committing transaction:",h),l(h)):(this.debug(e,"Transaction committed successfully"),c())})})})}catch(a){throw this.debug(e,"Error in insert:",a),a}}async update(t,e){if(!t||t.length===0)throw new Error("No data provided");let{tableName:s,primaryKey:i}=e;if(!i)throw new Error("Primary key is required for update operation");this.debug(e,"Starting update operation:",{tableName:s,primaryKey:i});try{let r=this.generateUpdateSql(t,s,i);return this.debug(e,"Generated update SQL:",r),new Promise((a,n)=>{let c=this.db.prepare(r);this.db.serialize(()=>{this.debug(e,"Beginning transaction"),this.db.run("BEGIN TRANSACTION"),t.forEach((l,d)=>{let g=Object.keys(l).filter(m=>m.toLowerCase()!==i.toLowerCase()).map(m=>l[m]);g.push(l[i]),this.debug(e,`Processing row ${d+1}/${t.length}:`),c.run(g)}),c.finalize(),this.db.run("COMMIT",l=>{l?(this.debug(e,"Error committing transaction:",l),n(l)):(this.debug(e,"Transaction committed successfully"),a())})})})}catch(r){throw this.debug(e,"Error in update:",r),r}}async upsert(t,e){if(!t||t.length===0)throw new Error("No data provided");let{tableName:s,primaryKey:i,isAlterTable:r}=e;this.debug(e,"Starting upsert operation:",{tableName:s,primaryKey:i,isAlterTable:r});try{await this.tableExists(s,e)?r&&(this.debug(e,"Table exists, checking for alterations"),await this.alterTable(t,s,e)):(this.debug(e,"Table does not exist, creating new table"),await this.createTable(t,s,i,e)),i&&(this.debug(e,"Creating index for primary key:",i),await this.addIndex(s,i,e));let n=this.generateUpsertSql(t,s,i);return this.debug(e,"Generated upsert SQL:",n),new Promise((c,l)=>{let d=this.db.prepare(n);this.db.serialize(()=>{this.debug(e,"Beginning transaction"),this.db.run("BEGIN TRANSACTION"),t.forEach((h,g)=>{let m=Object.values(h);this.debug(e,`Processing row ${g+1}/${t.length}:`,m.length),d.run(m)}),d.finalize(),this.db.run("COMMIT",h=>{h?(this.debug(e,"Error committing transaction:",h),l(h)):(this.debug(e,"Transaction committed successfully"),c())})})})}catch(a){throw this.debug(e,"Error in upsert:",a),a}}async query(t,e=[],s){return this.debug(s,"Executing query:",t,"with params:",e),new Promise((i,r)=>{this.db.all(t,e,(a,n)=>{a?(this.debug(s,"Error executing query:",a),r(a)):(this.debug(s,"Query results:",n.length),i(n))})})}},
|
6
|
+
WHERE "${s}"=?`}async createTable(t,e,s,i){let r=this.generateCreateTableSql(t,e,s);if(!r)throw new Error("No data provided for table creation");return this.debug(i,"Creating table with SQL:",r),new Promise((a,n)=>{this.db.run(r,c=>{c?(this.debug(i,"Error creating table:",c),n(c)):(this.debug(i,"Table created successfully"),a())})})}async addIndex(t,e,s){let i=`CREATE INDEX IF NOT EXISTS idx_${t}_${e} ON "${t}" ("${e}")`;return this.debug(s,"Creating index with SQL:",i),new Promise((r,a)=>{this.db.run(i,n=>{n?(this.debug(s,"Error creating index:",n),a(n)):(this.debug(s,"Index created successfully"),r())})})}async tableExists(t,e){let s="SELECT name FROM sqlite_master WHERE type='table' AND name=?";return this.debug(e,"Checking table existence:",s,[t]),new Promise((i,r)=>{this.db.get(s,[t],(a,n)=>{a?(this.debug(e,"Error checking table existence:",a),r(a)):(this.debug(e,"Table exists:",!!n),i(!!n))})})}async alterTable(t,e,s){this.debug(s,"Checking columns for table:",e);let r=(await this.query(`PRAGMA table_info("${e}");`,[],s)).map(c=>c.name),n=Object.keys(t[0]).filter(c=>!r.includes(c));if(this.debug(s,"Columns to add:",n),n.length>0)for(let c of n){let l=`ALTER TABLE "${e}" ADD COLUMN "${c}" TEXT;`;this.debug(s,"Altering table with SQL:",l),await new Promise((d,h)=>{this.db.run(l,g=>{g?(this.debug(s,"Error altering table:",g),h(g)):(this.debug(s,`Column "${c}" added successfully`),d())})})}}async insert(t,e){if(!t||t.length===0)throw new Error("No data provided");let{tableName:s,primaryKey:i,isAlterTable:r}=e;this.debug(e,"Starting insert operation:",{tableName:s,primaryKey:i,isAlterTable:r});try{await this.tableExists(s,e)?r&&(this.debug(e,"Table exists, checking for alterations"),await this.alterTable(t,s,e)):(this.debug(e,"Table does not exist, creating new table"),await this.createTable(t,s,i,e));let n=this.generateInsertSql(t,s);return this.debug(e,"Generated insert SQL:",n),new Promise((c,l)=>{let d=this.db.prepare(n);this.db.serialize(()=>{this.debug(e,"Beginning transaction"),this.db.run("BEGIN TRANSACTION"),t.forEach((h,g)=>{let m=Object.values(h);this.debug(e,`Processing row ${g+1}/${t.length}:`),d.run(m)}),d.finalize(),this.db.run("COMMIT",h=>{h?(this.debug(e,"Error committing transaction:",h),l(h)):(this.debug(e,"Transaction committed successfully"),c())})})})}catch(a){throw this.debug(e,"Error in insert:",a),a}}async update(t,e){if(!t||t.length===0)throw new Error("No data provided");let{tableName:s,primaryKey:i}=e;if(!i)throw new Error("Primary key is required for update operation");this.debug(e,"Starting update operation:",{tableName:s,primaryKey:i});try{let r=this.generateUpdateSql(t,s,i);return this.debug(e,"Generated update SQL:",r),new Promise((a,n)=>{let c=this.db.prepare(r);this.db.serialize(()=>{this.debug(e,"Beginning transaction"),this.db.run("BEGIN TRANSACTION"),t.forEach((l,d)=>{let g=Object.keys(l).filter(m=>m.toLowerCase()!==i.toLowerCase()).map(m=>l[m]);g.push(l[i]),this.debug(e,`Processing row ${d+1}/${t.length}:`),c.run(g)}),c.finalize(),this.db.run("COMMIT",l=>{l?(this.debug(e,"Error committing transaction:",l),n(l)):(this.debug(e,"Transaction committed successfully"),a())})})})}catch(r){throw this.debug(e,"Error in update:",r),r}}async upsert(t,e){if(!t||t.length===0)throw new Error("No data provided");let{tableName:s,primaryKey:i,isAlterTable:r}=e;this.debug(e,"Starting upsert operation:",{tableName:s,primaryKey:i,isAlterTable:r});try{await this.tableExists(s,e)?r&&(this.debug(e,"Table exists, checking for alterations"),await this.alterTable(t,s,e)):(this.debug(e,"Table does not exist, creating new table"),await this.createTable(t,s,i,e)),i&&(this.debug(e,"Creating index for primary key:",i),await this.addIndex(s,i,e));let n=this.generateUpsertSql(t,s,i);return this.debug(e,"Generated upsert SQL:",n),new Promise((c,l)=>{let d=this.db.prepare(n);this.db.serialize(()=>{this.debug(e,"Beginning transaction"),this.db.run("BEGIN TRANSACTION"),t.forEach((h,g)=>{let m=Object.values(h);this.debug(e,`Processing row ${g+1}/${t.length}:`,m.length),d.run(m)}),d.finalize(),this.db.run("COMMIT",h=>{h?(this.debug(e,"Error committing transaction:",h),l(h)):(this.debug(e,"Transaction committed successfully"),c())})})})}catch(a){throw this.debug(e,"Error in upsert:",a),a}}async query(t,e=[],s){return this.debug(s,"Executing query:",t,"with params:",e),new Promise((i,r)=>{this.db.all(t,e,(a,n)=>{a?(this.debug(s,"Error executing query:",a),r(a)):(this.debug(s,"Query results:",n.length),i(n))})})}},x=async(u,t)=>{let{dbPath:e,tableName:s,primaryKey:i,isAlterTable:r}=t,a=new p(e);try{await a.upsert(u,t),console.log(`Data saved to ${s} successfully`)}catch(n){console.error(n)}finally{await a.close()}};T.exports={SqliteUtil:p,sqliteUpsert:x}});var S=_chunkNEJSZOZXjs.b.call(void 0, (R,w)=>{var q=_chunkNEJSZOZXjs.a.call(void 0, "fs"),o=_chunkNEJSZOZXjs.a.call(void 0, "path"),C=_chunkNEJSZOZXjs.a.call(void 0, "glob");function N(u){u=o.resolve(u);let t=[];try{return C.sync(o.join(u,"**"),{ignore:["**/node_modules/**","**/py_modules/**","**/vendor/**","**/.ipynb_checkpoints/**","**/.nuxt/**","**/tmp/**","**/dist/**","**/cache/**","**/.angular/**","**/.cache/**","**/.sfdx/**","**/.sf/**","**/.DS_Store","**/.AppleDouble","**/.LSOverride"],windowsPathsNoEscape:!0,nodir:!0}).forEach(s=>{let i=q.statSync(s);if(i.isFile()){let r={id:s,dir:o.parse(s).dir,fileName:o.parse(s).name,extension:o.parse(s).ext,dir1:o.basename(o.dirname(s)),dir2:o.basename(o.dirname(o.dirname(s))),dir3:o.basename(o.dirname(o.dirname(o.dirname(s)))),dir4:o.basename(o.dirname(o.dirname(o.dirname(o.dirname(s))))),size:i.size};t.push(r)}}),t}catch(e){return console.error("Error reading directory:",e),[]}}w.exports={getFilesInfo:N}});var{sqliteUpsert:O}=y(),{getFilesInfo:A}=S(),k=_chunkNEJSZOZXjs.a.call(void 0, "path"),L={command:"*",describe:"ls1",builder:{input:{alias:"i",describe:"input dir",demandOption:!0,type:"string"},output:{alias:"o",describe:"output",demandOption:!1,type:"string"},table:{alias:"t",describe:"table",demandOption:!1,default:"sys_resource",type:"string"}},handler(u){(async()=>{let t=A(u.input);u.output&&u.output.endsWith(".db")?O(t,{dbPath:u.output,tableName:u.table,primaryKey:"id",isAlterTable:!0}):console.log(JSON.stringify(t,null,2))})()}},f=()=>{let u=_chunkNEJSZOZXjs.a.call(void 0, "yargs").scriptName("ls1");u.command(L);let t=u.parse()};f();
|