Skip to content

Commit

Permalink
deprecated the query
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Nov 21, 2024
1 parent b977e9c commit acff5c5
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/connections/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class BigQueryConnection extends SqlConnection {
* @param parameters - An object containing the parameters to be used in the query.
* @returns Promise<{ data: any, error: Error | null }>
*/
async query<T = Record<string, unknown>>(
async internalQuery<T = Record<string, unknown>>(
query: Query
): Promise<QueryResult<T>> {
try {
Expand Down
5 changes: 4 additions & 1 deletion src/connections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export abstract class Connection {

// Retrieve metadata about the database, useful for introspection.
abstract fetchDatabaseSchema(): Promise<Database>;
abstract raw(query: string): Promise<QueryResult>;
abstract raw(
query: string,
params?: Record<string, unknown> | unknown[]
): Promise<QueryResult>;
abstract testConnection(): Promise<{ error?: string }>;

// Connection common operations that will be used by Outerbase
Expand Down
2 changes: 1 addition & 1 deletion src/connections/motherduck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class DuckDBConnection extends PostgreBaseConnection {
* @param parameters - An object containing the parameters to be used in the query.
* @returns Promise<{ data: any, error: Error | null }>
*/
async query<T = Record<string, unknown>>(
async internalQuery<T = Record<string, unknown>>(
query: Query
): Promise<QueryResult<T>> {
const connection = this.connection;
Expand Down
2 changes: 1 addition & 1 deletion src/connections/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class MySQLConnection extends SqlConnection {
return super.mapDataType(dataType);
}

async query<T = Record<string, unknown>>(
async internalQuery<T = Record<string, unknown>>(
query: Query
): Promise<QueryResult<T>> {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/connections/postgre/postgresql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class PostgreSQLConnection extends PostgreBaseConnection {
await this.client.end();
}

async query<T = Record<string, unknown>>(
async internalQuery<T = Record<string, unknown>>(
query: Query
): Promise<QueryResult<T>> {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/connections/snowflake/snowflake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class SnowflakeConnection extends PostgreBaseConnection {
);
}

async query<T = Record<string, unknown>>(
async internalQuery<T = Record<string, unknown>>(
query: Query
): Promise<QueryResult<T>> {
try {
Expand Down
24 changes: 22 additions & 2 deletions src/connections/sql-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export abstract class SqlConnection extends Connection {
abstract dialect: AbstractDialect;
protected numberedPlaceholder = false;

abstract query<T = Record<string, unknown>>(
abstract internalQuery<T = Record<string, unknown>>(
query: Query
): Promise<QueryResult<T>>;

Expand All @@ -26,6 +26,23 @@ export abstract class SqlConnection extends Connection {
return dataType;
}

/**
* This is a deprecated function, use raw instead. We keep this for
* backward compatibility.
*
* @deprecated
* @param query
* @returns
*/
async query<T = Record<string, unknown>>(
query: Query
): Promise<QueryResult<T>> {
return (await this.raw(
query.query,
query.parameters
)) as QueryResult<T>;
}

async raw(
query: string,
params?: Record<string, unknown> | unknown[]
Expand All @@ -51,7 +68,10 @@ export abstract class SqlConnection extends Connection {

// Named placeholder
const { query: newQuery, bindings } = namedPlaceholder(query, params!);
return await this.query({ query: newQuery, parameters: bindings });
return await this.internalQuery({
query: newQuery,
parameters: bindings,
});
}

async select(
Expand Down
2 changes: 1 addition & 1 deletion src/connections/sqlite/cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class CloudflareD1Connection extends SqliteBaseConnection {
* @param parameters - An object containing the parameters to be used in the query.
* @returns Promise<{ data: any, error: Error | null }>
*/
async query<T = Record<string, unknown>>(
async internalQuery<T = Record<string, unknown>>(
query: Query
): Promise<QueryResult<T>> {
if (!this.apiKey) throw new Error('Cloudflare API key is not set');
Expand Down
2 changes: 1 addition & 1 deletion src/connections/sqlite/starbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class StarbaseConnection extends SqliteBaseConnection {
* @param parameters - An object containing the parameters to be used in the query.
* @returns Promise<{ data: any, error: Error | null }>
*/
async query<T = Record<string, unknown>>(
async internalQuery<T = Record<string, unknown>>(
query: Query
): Promise<QueryResult<T>> {
if (!this.url) throw new Error('Starbase URL is not set');
Expand Down
2 changes: 1 addition & 1 deletion src/connections/sqlite/turso.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class TursoConnection extends SqliteBaseConnection {
this.client = client;
}

async query<T = Record<string, unknown>>(
async internalQuery<T = Record<string, unknown>>(
query: Query
): Promise<QueryResult<T>> {
try {
Expand Down

0 comments on commit acff5c5

Please sign in to comment.