2023-01-27 03:22:44 -08:00
|
|
|
import type snowflake from 'snowflake-sdk';
|
2020-12-10 01:17:16 -08:00
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
export async function connect(conn: snowflake.Connection) {
|
2023-10-06 07:25:58 -07:00
|
|
|
return new Promise<void>((resolve, reject) => {
|
|
|
|
conn.connect((error) => (error ? reject(error) : resolve()));
|
2020-12-10 01:17:16 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
export async function destroy(conn: snowflake.Connection) {
|
2023-10-06 07:25:58 -07:00
|
|
|
return new Promise<void>((resolve, reject) => {
|
|
|
|
conn.destroy((error) => (error ? reject(error) : resolve()));
|
2020-12-10 01:17:16 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
export async function execute(
|
|
|
|
conn: snowflake.Connection,
|
|
|
|
sqlText: string,
|
|
|
|
binds: snowflake.InsertBinds,
|
|
|
|
) {
|
2023-10-06 07:25:58 -07:00
|
|
|
return new Promise<any[] | undefined>((resolve, reject) => {
|
2020-12-10 01:17:16 -08:00
|
|
|
conn.execute({
|
|
|
|
sqlText,
|
|
|
|
binds,
|
2023-10-06 07:25:58 -07:00
|
|
|
complete: (error, stmt, rows) => (error ? reject(error) : resolve(rows)),
|
2020-12-10 01:17:16 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|