budibase/packages/server/src/integrations/snowflake.ts

100 lines
2.1 KiB
TypeScript
Raw Normal View History

import { Integration, QueryType, SqlQuery } from "@budibase/types"
2022-06-01 12:41:41 +02:00
import { Snowflake } from "snowflake-promise"
2022-05-30 22:13:45 +02:00
module SnowflakeModule {
interface SnowflakeConfig {
account: string
username: string
password: string
warehouse: string
database: string
schema: string
}
const SCHEMA: Integration = {
docs: "https://developers.snowflake.com/",
description:
"Snowflake is a solution for data warehousing, data lakes, data engineering, data science, data application development, and securely sharing and consuming shared data.",
friendlyName: "Snowflake",
2022-06-23 12:35:57 +02:00
type: "Relational",
2022-05-30 22:13:45 +02:00
datasource: {
account: {
type: "string",
2022-05-30 22:13:45 +02:00
required: true,
},
username: {
type: "string",
2022-05-30 22:13:45 +02:00
required: true,
},
password: {
type: "password",
2022-05-30 22:13:45 +02:00
required: true,
},
warehouse: {
type: "string",
2022-05-30 22:13:45 +02:00
required: true,
},
database: {
type: "string",
2022-05-30 22:13:45 +02:00
required: true,
},
schema: {
type: "string",
2022-05-30 22:13:45 +02:00
required: true,
},
},
query: {
create: {
type: QueryType.SQL,
2022-05-30 22:13:45 +02:00
},
read: {
type: QueryType.SQL,
2022-05-30 22:13:45 +02:00
},
update: {
type: QueryType.SQL,
2022-05-30 22:13:45 +02:00
},
delete: {
type: QueryType.SQL,
2022-05-30 22:13:45 +02:00
},
},
}
class SnowflakeIntegration {
2022-06-01 12:41:41 +02:00
private client: Snowflake
2022-05-30 22:13:45 +02:00
constructor(config: SnowflakeConfig) {
2022-06-01 12:41:41 +02:00
this.client = new Snowflake(config)
2022-05-30 22:13:45 +02:00
}
2022-05-31 14:10:16 +02:00
async internalQuery(query: SqlQuery) {
2022-06-01 12:41:41 +02:00
await this.client.connect()
try {
return await this.client.execute(query.sql)
} catch (err: any) {
throw err?.message.split(":")[1] || err?.message
}
2022-05-30 22:13:45 +02:00
}
2022-05-31 14:10:16 +02:00
async create(query: SqlQuery) {
return this.internalQuery(query)
}
async read(query: SqlQuery) {
return this.internalQuery(query)
}
async update(query: SqlQuery) {
return this.internalQuery(query)
}
async delete(query: SqlQuery) {
return this.internalQuery(query)
}
2022-05-30 22:13:45 +02:00
}
module.exports = {
schema: SCHEMA,
integration: SnowflakeIntegration,
}
}