@carllee1983/dbcli 1.30.0 → 1.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -81224,7 +81224,7 @@ var {
81224
81224
  // package.json
81225
81225
  var package_default = {
81226
81226
  name: "@carllee1983/dbcli",
81227
- version: "1.30.0",
81227
+ version: "1.31.0",
81228
81228
  description: "Database CLI for AI agents",
81229
81229
  type: "module",
81230
81230
  publishConfig: {
package/dist/core.d.ts CHANGED
@@ -354,6 +354,40 @@ export declare class AdapterFactory {
354
354
  static createRedisAdapter(options: ConnectionOptions, blacklistRules?: string[], maskRules?: RedisMaskRule[]): QueryableAdapter;
355
355
  static createElasticsearchAdapter(options: ConnectionOptions): QueryableAdapter;
356
356
  }
357
+ /**
358
+ * Type definitions for data modification operations
359
+ * Defines results and options for data modification (INSERT, UPDATE, DELETE) operations
360
+ */
361
+ /**
362
+ * Result of a data execution operation
363
+ * Used to wrap the execution result and metadata of data modification operations
364
+ */
365
+ export interface DataExecutionResult {
366
+ /** Execution status: success or error */
367
+ status: "success" | "error";
368
+ /** Type of operation executed */
369
+ operation: "insert" | "update" | "delete";
370
+ /** Number of rows affected */
371
+ rows_affected: number;
372
+ /** Execution timestamp in ISO 8601 format */
373
+ timestamp?: string;
374
+ /** Generated SQL statement (for confirmation and error messages) */
375
+ sql?: string;
376
+ /** Error message (only when status is 'error') */
377
+ error?: string;
378
+ }
379
+ /**
380
+ * Data execution options
381
+ * Controls how data modification operations are executed
382
+ */
383
+ export interface DataExecutionOptions {
384
+ /** Dry run mode: display SQL without executing */
385
+ dryRun?: boolean;
386
+ /** Skip confirmation prompt */
387
+ force?: boolean;
388
+ /** Verbose output */
389
+ verbose?: boolean;
390
+ }
357
391
  interface SqlConnectionConfig {
358
392
  system: "postgresql" | "mysql" | "mariadb";
359
393
  host: string | {
@@ -2544,6 +2578,82 @@ export declare class QueryExecutor {
2544
2578
  limitValue?: number;
2545
2579
  }): Promise<QueryResult<Record<string, unknown>>>;
2546
2580
  }
2581
+ /**
2582
+ * DataExecutor class for executing INSERT, UPDATE, DELETE operations
2583
+ */
2584
+ export declare class DataExecutor {
2585
+ private adapter;
2586
+ private permission;
2587
+ private dbSystem;
2588
+ private blacklistValidator?;
2589
+ constructor(adapter: DatabaseAdapter, permission: Permission, dbSystem?: "postgresql" | "mysql", blacklistValidator?: BlacklistValidator | undefined);
2590
+ /**
2591
+ * Build a parameterized INSERT SQL statement
2592
+ * Returns {sql, params} form to prevent SQL injection
2593
+ *
2594
+ * @param tableName Table name
2595
+ * @param data Data object to insert {column: value, ...}
2596
+ * @param schema Table schema
2597
+ * @returns Parameterized SQL and parameters array
2598
+ * @throws Error if a data column is not found in the table schema
2599
+ */
2600
+ buildInsertSql(tableName: string, data: Record<string, unknown>, schema: TableSchema): {
2601
+ sql: string;
2602
+ params: (string | number | boolean | null)[];
2603
+ };
2604
+ /**
2605
+ * Execute an INSERT operation
2606
+ * Enforces permission check, builds SQL, shows confirmation prompt, executes
2607
+ *
2608
+ * @param tableName Table name
2609
+ * @param data Data object to insert
2610
+ * @param schema Table schema
2611
+ * @param options Execution options (dryRun, force, verbose)
2612
+ * @returns DataExecutionResult
2613
+ * @throws PermissionError if insufficient permissions
2614
+ * @throws Error if execution fails
2615
+ */
2616
+ executeInsert(tableName: string, data: Record<string, unknown>, schema: TableSchema, options?: DataExecutionOptions): Promise<DataExecutionResult>;
2617
+ /**
2618
+ * Execute an UPDATE operation
2619
+ * Enforces permission check, builds SQL, shows confirmation prompt, executes
2620
+ *
2621
+ * @param tableName Table name
2622
+ * @param data Updated data object
2623
+ * @param where WHERE clause condition object
2624
+ * @param schema Table schema
2625
+ * @param options Execution options
2626
+ * @returns DataExecutionResult
2627
+ */
2628
+ executeUpdate(tableName: string, data: Record<string, unknown>, where: Record<string, unknown>, schema: TableSchema, options?: DataExecutionOptions): Promise<DataExecutionResult>;
2629
+ /**
2630
+ * Execute a DELETE operation
2631
+ * Admin-only operation, requires strict permission check
2632
+ *
2633
+ * @param tableName Table name
2634
+ * @param where WHERE clause condition object
2635
+ * @param schema Table schema
2636
+ * @param options Execution options
2637
+ * @returns DataExecutionResult
2638
+ */
2639
+ executeDelete(tableName: string, where: Record<string, unknown>, schema: TableSchema, options?: DataExecutionOptions): Promise<DataExecutionResult>;
2640
+ /**
2641
+ * Get database system type (used to determine parameter placeholder and identifier quoting)
2642
+ */
2643
+ private getSystemType;
2644
+ /**
2645
+ * Get identifier quote character (for table names and column names)
2646
+ */
2647
+ private getQuoteChar;
2648
+ /**
2649
+ * Build a parameterized UPDATE SQL statement
2650
+ */
2651
+ private buildUpdateSql;
2652
+ /**
2653
+ * Build a parameterized DELETE SQL statement
2654
+ */
2655
+ private buildDeleteSql;
2656
+ }
2547
2657
  interface SchemaIndex {
2548
2658
  tables: Record<string, {
2549
2659
  location: "hot" | "cold";