@@ -2,6 +2,7 @@ import { open, Database } from 'sqlite';
22import { EventEmitter } from 'events' ;
33import { isJsonObject } from 'tiny-essentials' ;
44
5+ import { validatePostgresParams } from './Utils.mjs' ;
56import { pg , sqlite3 } from './Modules.mjs' ;
67import PuddySqlEngine from './PuddySqlEngine.mjs' ;
78import PuddySqlQuery from './PuddySqlQuery.mjs' ;
@@ -420,8 +421,7 @@ class PuddySqlInstance extends PuddySqlEngine {
420421 * @throws {Error } If the table has already been initialized.
421422 */
422423 async initTable ( settings = { } , tableData = [ ] ) {
423- if ( ! isJsonObject ( settings ) )
424- throw new Error ( 'settings must be a plain object' ) ;
424+ if ( ! isJsonObject ( settings ) ) throw new Error ( 'settings must be a plain object' ) ;
425425 if ( typeof settings . name !== 'string' ) throw new Error ( 'settings.name must be a string' ) ;
426426 if ( ! this . #tables[ settings . name ] ) {
427427 const newTable = new PuddySqlQuery ( ) ;
@@ -591,10 +591,9 @@ class PuddySqlInstance extends PuddySqlEngine {
591591 * @returns {void }
592592 */
593593 const rejectConnection = ( reject , err ) => {
594- if ( isConnectionError ( err ) ) event . emit ( 'connection-error' , err ) ;
594+ if ( isConnectionError ( err ) ) this . #events . emit ( 'connection-error' , err ) ;
595595 reject ( err ) ;
596596 } ;
597- const event = this . #events;
598597 const getId = ( ) => this . #debugCount++ ;
599598 const isDebug = ( ) => this . #debug;
600599
@@ -644,6 +643,7 @@ class PuddySqlInstance extends PuddySqlEngine {
644643 */
645644 this . all = async function ( query , params = [ ] , debugName = '' ) {
646645 return new Promise ( ( resolve , reject ) => {
646+ validatePostgresParams ( query , params , reject ) ;
647647 const id = getId ( ) ;
648648 sendSqlDebug ( id , debugName , query , params ) ;
649649 db . all ( query , params )
@@ -664,6 +664,7 @@ class PuddySqlInstance extends PuddySqlEngine {
664664 */
665665 this . get = async function ( query , params = [ ] , debugName = '' ) {
666666 return new Promise ( ( resolve , reject ) => {
667+ validatePostgresParams ( query , params , reject ) ;
667668 const id = getId ( ) ;
668669 sendSqlDebug ( id , debugName , query , params ) ;
669670 db . get ( query , params )
@@ -684,6 +685,7 @@ class PuddySqlInstance extends PuddySqlEngine {
684685 */
685686 this . run = async function ( query , params , debugName = '' ) {
686687 return new Promise ( ( resolve , reject ) => {
688+ validatePostgresParams ( query , params , reject ) ;
687689 const id = getId ( ) ;
688690 sendSqlDebug ( id , debugName , query , params ) ;
689691 db . run ( query , params )
@@ -756,9 +758,8 @@ class PuddySqlInstance extends PuddySqlEngine {
756758 * @returns {void }
757759 */
758760 const rejectConnection = ( err ) => {
759- if ( isConnectionError ( err ) ) event . emit ( 'connection-error' , err ) ;
761+ if ( isConnectionError ( err ) ) this . #events . emit ( 'connection-error' , err ) ;
760762 } ;
761- const event = this . #events;
762763 db . on ( 'error' , rejectConnection ) ;
763764
764765 const getId = ( ) => this . #debugCount++ ;
@@ -810,6 +811,7 @@ class PuddySqlInstance extends PuddySqlEngine {
810811 */
811812 this . all = async function ( query , params = [ ] , debugName = '' ) {
812813 try {
814+ validatePostgresParams ( query , params ) ;
813815 const id = getId ( ) ;
814816 sendSqlDebug ( id , debugName , query , params ) ;
815817 const res = await db . query ( query , params ) ;
@@ -830,6 +832,7 @@ class PuddySqlInstance extends PuddySqlEngine {
830832 */
831833 this . get = async function ( query , params = [ ] , debugName = '' ) {
832834 try {
835+ validatePostgresParams ( query , params ) ;
833836 const id = getId ( ) ;
834837 sendSqlDebug ( id , debugName , query , params ) ;
835838 const res = await db . query ( query , params ) ;
@@ -852,6 +855,7 @@ class PuddySqlInstance extends PuddySqlEngine {
852855 */
853856 this . run = async function ( query , params , debugName = '' ) {
854857 try {
858+ validatePostgresParams ( query , params ) ;
855859 const id = getId ( ) ;
856860 sendSqlDebug ( id , debugName , query , params ) ;
857861 const res = await db . query ( query , params ) ;
0 commit comments