driftsql 1.0.27 → 1.0.28

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.
@@ -0,0 +1,17 @@
1
+ import type { DatabaseDriver, QueryResult } from '../types';
2
+ interface SurrealConfig {
3
+ url: string;
4
+ namespace: string;
5
+ database: string;
6
+ auth: {
7
+ username: string;
8
+ password: string;
9
+ };
10
+ }
11
+ export declare class SurrealDriver implements DatabaseDriver {
12
+ private client;
13
+ constructor(config: SurrealConfig);
14
+ query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
15
+ close(): Promise<void>;
16
+ }
17
+ export {};
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export { MySQLDriver } from './drivers/mysql';
6
6
  export { NeonDriver } from './drivers/neon';
7
7
  export { SqliteCloudDriver } from './drivers/sqlitecloud';
8
8
  export { inspectDB } from './pull';
9
+ export { SurrealDriver } from './drivers/surreal';
9
10
  export interface ClientOptions<T extends DatabaseDriver = DatabaseDriver> {
10
11
  driver: T;
11
12
  fallbackDrivers?: DatabaseDriver[];
package/dist/index.js CHANGED
@@ -45,4 +45,4 @@ import consola3 from"consola";function hasTransactionSupport(driver){return"tran
45
45
  `;for(const table of tables.rows){const interfaceName=table.table_name.charAt(0).toUpperCase()+table.table_name.slice(1);generatedTypes+=` ${table.table_name}: ${interfaceName};
46
46
  `}generatedTypes+=`}
47
47
 
48
- `;await fs.writeFile(outputFile,generatedTypes,"utf8");consola2.log(`TypeScript types written to ${outputFile}`);consola2.log(`Successfully processed ${processedTables} tables`)}catch(error){consola2.error("Fatal error during database inspection:",error);throw error}finally{await client.close()}};class SQLClient{primaryDriver;fallbackDrivers;constructor(options){this.primaryDriver=options.driver;this.fallbackDrivers=options.fallbackDrivers||[]}async query(sql,params){const drivers=[this.primaryDriver,...this.fallbackDrivers];let lastError;for(const driver of drivers){try{return await driver.query(sql,params)}catch(error){lastError=error;consola3.warn(`Query failed with ${driver.constructor.name}:`,error);continue}}throw lastError||new DatabaseError("All drivers failed to execute query","unknown")}async transaction(callback){if(!hasTransactionSupport(this.primaryDriver)){throw new DatabaseError("Primary driver does not support transactions",this.primaryDriver.constructor.name)}return await this.primaryDriver.transaction(async(transactionDriver)=>{const transactionClient=new SQLClient({driver:transactionDriver,fallbackDrivers:[]});return await callback(transactionClient)})}async prepare(sql){if(!hasPreparedStatementSupport(this.primaryDriver)){throw new DatabaseError("Primary driver does not support prepared statements",this.primaryDriver.constructor.name)}return await this.primaryDriver.prepare(sql)}async findFirst(table,where){if(!this.primaryDriver.findFirst)throw new DatabaseError("Primary driver does not support findFirst",this.primaryDriver.constructor.name);try{const response=await this.primaryDriver.findFirst(table,where);return response.rows[0]||null}catch(error){throw new QueryError("findFirst",`Error finding first in ${String(table)}`,error)}}async findMany(table,options){if(!this.primaryDriver.findMany)throw new DatabaseError("Primary driver does not support findMany",this.primaryDriver.constructor.name);try{const response=await this.primaryDriver.findMany(table,options);return response.rows}catch(error){throw new QueryError("findMany",`Error finding many in ${String(table)}`,error)}}async insert(table,data){if(!this.primaryDriver.insert)throw new DatabaseError("Primary driver does not support insert",this.primaryDriver.constructor.name);try{const response=await this.primaryDriver.insert(table,data);return response.rows[0]}catch(error){throw new QueryError("insert",`Error inserting into ${String(table)}`,error)}}async update(table,data,where){if(!this.primaryDriver.update)throw new DatabaseError("Primary driver does not support update",this.primaryDriver.constructor.name);try{const response=await this.primaryDriver.update(table,data,where);return response.rows[0]||null}catch(error){throw new QueryError("update",`Error updating ${String(table)}`,error)}}async delete(table,where){if(!this.primaryDriver.delete)throw new DatabaseError("Primary driver does not support delete",this.primaryDriver.constructor.name);try{const affectedRows=await this.primaryDriver.delete(table,where);return affectedRows}catch(error){throw new QueryError("delete",`Error deleting from ${String(table)}`,error)}}getDriver(){return this.primaryDriver}supportsTransactions(){return hasTransactionSupport(this.primaryDriver)}supportsPreparedStatements(){return hasPreparedStatementSupport(this.primaryDriver)}async close(){const drivers=[this.primaryDriver,...this.fallbackDrivers];await Promise.all(drivers.map((driver)=>driver.close().catch((err)=>consola3.warn(`Error closing ${driver.constructor.name}:`,err))))}}var DriftSQLClient=SQLClient;export{inspectDB,SqliteCloudDriver,SQLClient,PostgresDriver,NeonDriver,MySQLDriver,LibSQLDriver,DriftSQLClient};
48
+ `;await fs.writeFile(outputFile,generatedTypes,"utf8");consola2.log(`TypeScript types written to ${outputFile}`);consola2.log(`Successfully processed ${processedTables} tables`)}catch(error){consola2.error("Fatal error during database inspection:",error);throw error}finally{await client.close()}};import Surreal from"surrealdb";class SurrealDriver{client;constructor(config){this.client=new Surreal;this.client.connect(config.url,{namespace:config.namespace,database:config.database,auth:config.auth})}async query(sql,params){try{if(params)throw new QueryError("surreal",sql,new Error("SurrealDB does need params"));const dbResult=await this.client.query(sql);return{rows:dbResult,rowCount:dbResult.length}}catch(error){throw new QueryError("surreal",sql,error)}}async close(){await this.client.close()}}class SQLClient{primaryDriver;fallbackDrivers;constructor(options){this.primaryDriver=options.driver;this.fallbackDrivers=options.fallbackDrivers||[]}async query(sql,params){const drivers=[this.primaryDriver,...this.fallbackDrivers];let lastError;for(const driver of drivers){try{return await driver.query(sql,params)}catch(error){lastError=error;consola3.warn(`Query failed with ${driver.constructor.name}:`,error);continue}}throw lastError||new DatabaseError("All drivers failed to execute query","unknown")}async transaction(callback){if(!hasTransactionSupport(this.primaryDriver)){throw new DatabaseError("Primary driver does not support transactions",this.primaryDriver.constructor.name)}return await this.primaryDriver.transaction(async(transactionDriver)=>{const transactionClient=new SQLClient({driver:transactionDriver,fallbackDrivers:[]});return await callback(transactionClient)})}async prepare(sql){if(!hasPreparedStatementSupport(this.primaryDriver)){throw new DatabaseError("Primary driver does not support prepared statements",this.primaryDriver.constructor.name)}return await this.primaryDriver.prepare(sql)}async findFirst(table,where){if(!this.primaryDriver.findFirst)throw new DatabaseError("Primary driver does not support findFirst",this.primaryDriver.constructor.name);try{const response=await this.primaryDriver.findFirst(table,where);return response.rows[0]||null}catch(error){throw new QueryError("findFirst",`Error finding first in ${String(table)}`,error)}}async findMany(table,options){if(!this.primaryDriver.findMany)throw new DatabaseError("Primary driver does not support findMany",this.primaryDriver.constructor.name);try{const response=await this.primaryDriver.findMany(table,options);return response.rows}catch(error){throw new QueryError("findMany",`Error finding many in ${String(table)}`,error)}}async insert(table,data){if(!this.primaryDriver.insert)throw new DatabaseError("Primary driver does not support insert",this.primaryDriver.constructor.name);try{const response=await this.primaryDriver.insert(table,data);return response.rows[0]}catch(error){throw new QueryError("insert",`Error inserting into ${String(table)}`,error)}}async update(table,data,where){if(!this.primaryDriver.update)throw new DatabaseError("Primary driver does not support update",this.primaryDriver.constructor.name);try{const response=await this.primaryDriver.update(table,data,where);return response.rows[0]||null}catch(error){throw new QueryError("update",`Error updating ${String(table)}`,error)}}async delete(table,where){if(!this.primaryDriver.delete)throw new DatabaseError("Primary driver does not support delete",this.primaryDriver.constructor.name);try{const affectedRows=await this.primaryDriver.delete(table,where);return affectedRows}catch(error){throw new QueryError("delete",`Error deleting from ${String(table)}`,error)}}getDriver(){return this.primaryDriver}supportsTransactions(){return hasTransactionSupport(this.primaryDriver)}supportsPreparedStatements(){return hasPreparedStatementSupport(this.primaryDriver)}async close(){const drivers=[this.primaryDriver,...this.fallbackDrivers];await Promise.all(drivers.map((driver)=>driver.close().catch((err)=>consola3.warn(`Error closing ${driver.constructor.name}:`,err))))}}var DriftSQLClient=SQLClient;export{inspectDB,SurrealDriver,SqliteCloudDriver,SQLClient,PostgresDriver,NeonDriver,MySQLDriver,LibSQLDriver,DriftSQLClient};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "driftsql",
3
- "version": "1.0.27",
3
+ "version": "1.0.28",
4
4
  "main": "dist/index.js",
5
5
  "description": "A lightweight SQL client for TypeScript",
6
6
  "scripts": {
@@ -22,6 +22,7 @@
22
22
  "mysql2": "^3.14.3",
23
23
  "ora": "^8.2.0",
24
24
  "postgres": "^3.4.7",
25
+ "surrealdb": "^1.3.2",
25
26
  "zod": "^4.1.3"
26
27
  },
27
28
  "devDependencies": {