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) {
|
2024-01-17 07:08:50 -08:00
|
|
|
return await new Promise<void>((resolve, reject) => {
|
2023-10-06 07:25:58 -07:00
|
|
|
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) {
|
2024-01-17 07:08:50 -08:00
|
|
|
return await new Promise<void>((resolve, reject) => {
|
2023-10-06 07:25:58 -07:00
|
|
|
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,
|
|
|
|
) {
|
2024-01-17 07:08:50 -08:00
|
|
|
return await 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
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|