UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

221 lines • 8.34 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../../core/resource.mjs"; import * as TimeTravelAPI from "./time-travel.mjs"; import { BaseTimeTravel, TimeTravel, } from "./time-travel.mjs"; import { SinglePage, V4PagePaginationArray, } from "../../../core/pagination.mjs"; import { path } from "../../../internal/utils/path.mjs"; export var BaseDatabase = /* @__PURE__ */ (() => { class BaseDatabase extends 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(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(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(path `/accounts/${account_id}/d1/database`, (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(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(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(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(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(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(path `/accounts/${account_id}/d1/database/${databaseID}/query`, (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(path `/accounts/${account_id}/d1/database/${databaseID}/raw`, (SinglePage), { body, method: 'post', ...options }); } } BaseDatabase._key = Object.freeze(['d1', 'database']); return BaseDatabase; })(); export var Database = /* @__PURE__ */ (() => { class Database extends BaseDatabase { constructor() { super(...arguments); this.timeTravel = new TimeTravelAPI.TimeTravel(this._client); } } Database.TimeTravel = TimeTravel; Database.BaseTimeTravel = BaseTimeTravel; return Database; })(); //# sourceMappingURL=database.mjs.map