cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
src/resources/d1/database.ts
121lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. |
| 2 | |
| 3 | import * as Core from 'cloudflare/core'; |
| 4 | import { APIResource } from 'cloudflare/resource'; |
| 5 | import * as DatabaseAPI from 'cloudflare/resources/d1/database'; |
| 6 | |
| 7 | export class Database extends APIResource { |
| 8 | /** |
| 9 | * Returns the specified D1 database. |
| 10 | */ |
| 11 | retrieve( |
| 12 | accountIdentifier: string, |
| 13 | databaseIdentifier: string, |
| 14 | options?: Core.RequestOptions, |
| 15 | ): Core.APIPromise<DatabaseRetrieveResponse> { |
| 16 | return ( |
| 17 | this._client.get( |
| 18 | `/accounts/${accountIdentifier}/d1/database/${databaseIdentifier}`, |
| 19 | options, |
| 20 | ) as Core.APIPromise<{ result: DatabaseRetrieveResponse }> |
| 21 | )._thenUnwrap((obj) => obj.result); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Deletes the specified D1 database. |
| 26 | */ |
| 27 | delete( |
| 28 | accountIdentifier: string, |
| 29 | databaseIdentifier: string, |
| 30 | options?: Core.RequestOptions, |
| 31 | ): Core.APIPromise<DatabaseDeleteResponse | null> { |
| 32 | return ( |
| 33 | this._client.delete( |
| 34 | `/accounts/${accountIdentifier}/d1/database/${databaseIdentifier}`, |
| 35 | options, |
| 36 | ) as Core.APIPromise<{ result: DatabaseDeleteResponse | null }> |
| 37 | )._thenUnwrap((obj) => obj.result); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Returns the query result. |
| 42 | */ |
| 43 | query( |
| 44 | accountIdentifier: string, |
| 45 | databaseIdentifier: string, |
| 46 | body: DatabaseQueryParams, |
| 47 | options?: Core.RequestOptions, |
| 48 | ): Core.APIPromise<DatabaseQueryResponse> { |
| 49 | return ( |
| 50 | this._client.post(`/accounts/${accountIdentifier}/d1/database/${databaseIdentifier}/query`, { |
| 51 | body, |
| 52 | ...options, |
| 53 | }) as Core.APIPromise<{ result: DatabaseQueryResponse }> |
| 54 | )._thenUnwrap((obj) => obj.result); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | export interface DatabaseRetrieveResponse { |
| 59 | /** |
| 60 | * Specifies the timestamp the resource was created as an ISO8601 string. |
| 61 | */ |
| 62 | created_at?: unknown; |
| 63 | |
| 64 | /** |
| 65 | * The D1 database's size, in bytes. |
| 66 | */ |
| 67 | file_size?: number; |
| 68 | |
| 69 | name?: string; |
| 70 | |
| 71 | num_tables?: number; |
| 72 | |
| 73 | uuid?: string; |
| 74 | |
| 75 | version?: string; |
| 76 | } |
| 77 | |
| 78 | export type DatabaseDeleteResponse = unknown | string; |
| 79 | |
| 80 | export type DatabaseQueryResponse = Array<DatabaseQueryResponse.DatabaseQueryResponseItem>; |
| 81 | |
| 82 | export namespace DatabaseQueryResponse { |
| 83 | export interface DatabaseQueryResponseItem { |
| 84 | meta?: DatabaseQueryResponseItem.Meta; |
| 85 | |
| 86 | results?: Array<unknown>; |
| 87 | |
| 88 | success?: boolean; |
| 89 | } |
| 90 | |
| 91 | export namespace DatabaseQueryResponseItem { |
| 92 | export interface Meta { |
| 93 | changed_db?: boolean; |
| 94 | |
| 95 | changes?: number; |
| 96 | |
| 97 | duration?: number; |
| 98 | |
| 99 | last_row_id?: number; |
| 100 | |
| 101 | rows_read?: number; |
| 102 | |
| 103 | rows_written?: number; |
| 104 | |
| 105 | size_after?: number; |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | export interface DatabaseQueryParams { |
| 111 | sql: string; |
| 112 | |
| 113 | params?: Array<string>; |
| 114 | } |
| 115 | |
| 116 | export namespace Database { |
| 117 | export import DatabaseRetrieveResponse = DatabaseAPI.DatabaseRetrieveResponse; |
| 118 | export import DatabaseDeleteResponse = DatabaseAPI.DatabaseDeleteResponse; |
| 119 | export import DatabaseQueryResponse = DatabaseAPI.DatabaseQueryResponse; |
| 120 | export import DatabaseQueryParams = DatabaseAPI.DatabaseQueryParams; |
| 121 | } |
| 122 | |