UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

227 lines • 8.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Database = exports.BaseDatabase = void 0; const tslib_1 = require("../../../internal/tslib.js"); // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. const resource_1 = require("../../../core/resource.js"); const TimeTravelAPI = tslib_1.__importStar(require("./time-travel.js")); const time_travel_1 = require("./time-travel.js"); const pagination_1 = require("../../../core/pagination.js"); const path_1 = require("../../../internal/utils/path.js"); var BaseDatabase = /* @__PURE__ */ (() => { class BaseDatabase extends resource_1.APIResource { /** * Create a new D1 database in your account. * * @example * ```ts * const d1 = await client.d1.database.create({ * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * name: 'my-database', * }); * ``` */ create(params, options) { const { account_id, ...body } = params; return this._client.post((0, path_1.path) `/accounts/${account_id}/d1/database`, { body, ...options })._thenUnwrap((obj) => obj.result); } /** * Update a D1 database's configuration. * * @example * ```ts * const d1 = await client.d1.database.update( * 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * read_replication: { mode: 'auto' }, * }, * ); * ``` */ update(databaseID, params, options) { const { account_id, ...body } = params; return this._client.put((0, path_1.path) `/accounts/${account_id}/d1/database/${databaseID}`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * List D1 databases in your account. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const databaseListResponse of client.d1.database.list( * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * )) { * // ... * } * ``` */ list(params, options) { const { account_id, ...query } = params; return this._client.getAPIList((0, path_1.path) `/accounts/${account_id}/d1/database`, (pagination_1.V4PagePaginationArray), { query, ...options }); } /** * Delete a D1 database. * * @example * ```ts * const database = await client.d1.database.delete( * 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ delete(databaseID, params, options) { const { account_id } = params; return this._client.delete((0, path_1.path) `/accounts/${account_id}/d1/database/${databaseID}`, options)._thenUnwrap((obj) => obj.result); } /** * Partially update a D1 database's configuration. * * @example * ```ts * const d1 = await client.d1.database.edit( * 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ edit(databaseID, params, options) { const { account_id, ...body } = params; return this._client.patch((0, path_1.path) `/accounts/${account_id}/d1/database/${databaseID}`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Export the SQL contents of a D1 database and return a URL where they can be * downloaded. Note: this process may take some time for larger DBs, during which * your D1 will be unavailable to serve queries. To avoid blocking your DB * unnecessarily, an in-progress export must be continually polled or will * automatically cancel. * * @example * ```ts * const response = await client.d1.database.export( * 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * output_format: 'polling', * }, * ); * ``` */ export(databaseID, params, options) { const { account_id, ...body } = params; return this._client.post((0, path_1.path) `/accounts/${account_id}/d1/database/${databaseID}/export`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Get details for a specific D1 database. * * @example * ```ts * const d1 = await client.d1.database.get( * 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ get(databaseID, params, options) { const { account_id, ...query } = params; return this._client.get((0, path_1.path) `/accounts/${account_id}/d1/database/${databaseID}`, { query, ...options, })._thenUnwrap((obj) => obj.result); } /** * Generate a temporary URL for uploading an SQL file to, then instruct the D1 to * import it and poll it for status updates. Imports block the D1 for their * duration. * * @example * ```ts * const response = await client.d1.database.import( * 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * action: 'init', * etag: 'etag', * }, * ); * ``` */ import(databaseID, params, options) { const { account_id, ...body } = params; return this._client.post((0, path_1.path) `/accounts/${account_id}/d1/database/${databaseID}/import`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Execute a SQL query against a D1 database and return results as objects. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const queryResult of client.d1.database.query( * 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * sql: 'SELECT * FROM myTable WHERE field = ? OR field = ?;', * }, * )) { * // ... * } * ``` */ query(databaseID, params, options) { const { account_id, ...body } = params; return this._client.getAPIList((0, path_1.path) `/accounts/${account_id}/d1/database/${databaseID}/query`, (pagination_1.SinglePage), { body, method: 'post', ...options }); } /** * Execute a SQL query against a D1 database and return result rows as arrays * rather than objects. This is a performance-optimized version of the /query * endpoint. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const databaseRawResponse of client.d1.database.raw( * 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * sql: 'SELECT * FROM myTable WHERE field = ? OR field = ?;', * }, * )) { * // ... * } * ``` */ raw(databaseID, params, options) { const { account_id, ...body } = params; return this._client.getAPIList((0, path_1.path) `/accounts/${account_id}/d1/database/${databaseID}/raw`, (pagination_1.SinglePage), { body, method: 'post', ...options }); } } BaseDatabase._key = Object.freeze(['d1', 'database']); return BaseDatabase; })(); exports.BaseDatabase = BaseDatabase; var Database = /* @__PURE__ */ (() => { class Database extends BaseDatabase { constructor() { super(...arguments); this.timeTravel = new TimeTravelAPI.TimeTravel(this._client); } } Database.TimeTravel = time_travel_1.TimeTravel; Database.BaseTimeTravel = time_travel_1.BaseTimeTravel; return Database; })(); exports.Database = Database; //# sourceMappingURL=database.js.map