mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-27 08:27:23 +00:00
* Feature: Prometheus plugin (#13161) * prometheus plugin * added existing props * Host and database can be dynamically configured in query builder for PostgreSQL and MySQL data sources (#13163) * Fix: Postgresql datasource tries to connect via ssl even when ssl toggle is off (#13167) * The ability to provide a partition key for deleting items in CosmosDB datasource has been enabled (#13166) * Feature: Ability to configure the database name in Redis datasource (#13165) * Fix: Avoid setting Content-Type header for requests without body and configure different host for all environments in OpenAPI [PRE-RELEASE] (#13230) * Send content-type only with body in request * Persist OpenAPI parameters per operation only * Configure different host * Add disable styles to the select input * Feat: New fields 'client id' and 'client secret' have been introduced in the Slack datasource configuration page in pre-release (#13162) * Update slack frontend * Update slack backend to handle custom creds * Add backfill migrations * Dynamically change dropdown according to versions * Change migration file name * Correctly access scope in chat:write logic --------- Co-authored-by: Akshay Sasidharan <akshaysasidharan93@gmail.com> Co-authored-by: Parth <108089718+parthy007@users.noreply.github.com> Co-authored-by: Akshay <akshaysasidrn@gmail.com>
146 lines
4 KiB
TypeScript
146 lines
4 KiB
TypeScript
import { Container, CosmosClient } from '@azure/cosmos';
|
|
|
|
export async function listDatabases(client: CosmosClient): Promise<object> {
|
|
return new Promise((resolve, reject) => {
|
|
client.databases
|
|
.readAll({})
|
|
.fetchAll()
|
|
.then((data) => {
|
|
const databases = data.resources.map((db) => db.id);
|
|
resolve(databases);
|
|
})
|
|
.catch((err) => {
|
|
reject(err);
|
|
})
|
|
.finally(() => client.dispose());
|
|
});
|
|
}
|
|
|
|
export function listContainers(client: CosmosClient, database: string) {
|
|
return new Promise((resolve, reject) => {
|
|
lookUpDatabase(client, database)
|
|
.then(() => {
|
|
client
|
|
.database(database)
|
|
.containers.readAll()
|
|
.fetchAll()
|
|
.then((data) => {
|
|
const containers = data.resources.map((container) => container.id);
|
|
resolve(containers);
|
|
})
|
|
.catch((err) => {
|
|
reject(err);
|
|
});
|
|
})
|
|
.catch((err) => {
|
|
reject(err);
|
|
})
|
|
|
|
.finally(() => client.dispose());
|
|
});
|
|
}
|
|
|
|
export function insertItems(client: CosmosClient, database: string, containerId: string, items: []) {
|
|
return new Promise((resolve, reject) => {
|
|
lookUpContainer(client, database, containerId)
|
|
.then((container: Container) => {
|
|
items.forEach(async (item) => {
|
|
await container.items.create(item);
|
|
});
|
|
resolve({ message: 'Items inserted' });
|
|
})
|
|
.catch((err) => {
|
|
reject(err);
|
|
})
|
|
.finally(() => client.dispose());
|
|
});
|
|
}
|
|
|
|
export function deleteItem(client: CosmosClient, database: string, containerId: string, itemId, partitionKey?: string) {
|
|
return new Promise((resolve, reject) => {
|
|
lookUpContainer(client, database, containerId)
|
|
.then((container: Container) => {
|
|
partitionKey
|
|
? container
|
|
.item(itemId, partitionKey)
|
|
.delete()
|
|
.then(() => {
|
|
resolve({ message: 'Item deleted' });
|
|
})
|
|
.catch((err) => {
|
|
reject(err);
|
|
})
|
|
: container
|
|
.item(itemId)
|
|
.delete()
|
|
.then(() => {
|
|
resolve({ message: 'Item deleted' });
|
|
})
|
|
.catch((err) => {
|
|
reject(err);
|
|
});
|
|
})
|
|
.catch((err) => {
|
|
reject(err);
|
|
})
|
|
.finally(() => client.dispose());
|
|
});
|
|
}
|
|
|
|
export function queryDatabase(client: CosmosClient, database: string, containerId: string, query: string) {
|
|
return new Promise((resolve, reject) => {
|
|
lookUpContainer(client, database, containerId)
|
|
.then((container: Container) => {
|
|
container.items
|
|
.query(query)
|
|
.fetchAll()
|
|
.then((data) => {
|
|
resolve(data.resources);
|
|
})
|
|
.catch((err) => {
|
|
reject(err);
|
|
});
|
|
})
|
|
.catch((err) => {
|
|
reject(err);
|
|
})
|
|
.finally(() => client.dispose());
|
|
});
|
|
}
|
|
|
|
export async function getItem(client: CosmosClient, database: string, containerId: string, itemId: string) {
|
|
const { container } = await client.database(database).containers.createIfNotExists({ id: containerId });
|
|
|
|
return (await container.item(itemId).read()).resource;
|
|
}
|
|
|
|
function lookUpContainer(client: CosmosClient, database: string, containerId: string) {
|
|
return new Promise((resolve, reject) => {
|
|
client
|
|
.database(database)
|
|
.containers.createIfNotExists({ id: containerId })
|
|
.then((data) => {
|
|
resolve(data.container);
|
|
})
|
|
.catch((err) => {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
|
|
function lookUpDatabase(client: CosmosClient, database: string) {
|
|
return new Promise((resolve, reject) => {
|
|
client.databases
|
|
.createIfNotExists({ id: database })
|
|
.then((data) => {
|
|
resolve(data);
|
|
})
|
|
.catch((err) => {
|
|
reject(err);
|
|
});
|
|
})
|
|
.catch((err) => {
|
|
throw new Error(err);
|
|
})
|
|
.finally(() => client.dispose());
|
|
}
|