Skip to content
File

Blob: types/defines/hyperdrive.d.ts

typescript50 lines
1interface Hyperdrive {
2 /**
3 * Connect directly to Hyperdrive as if it's your database, returning a TCP socket.
4 *
5 * Calling this method returns an identical socket to if you call
6 * `connect("host:port")` using the `host` and `port` fields from this object.
7 * Pick whichever approach works better with your preferred DB client library.
8 *
9 * Note that this socket is not yet authenticated -- it's expected that your
10 * code (or preferably, the client library of your choice) will authenticate
11 * using the information in this class's readonly fields.
12 */
13 connect(): Socket;
14 
15 /**
16 * A valid DB connection string that can be passed straight into the typical
17 * client library/driver/ORM. This will typically be the easiest way to use
18 * Hyperdrive.
19 */
20 readonly connectionString: string;
21 
22 /*
23 * A randomly generated hostname that is only valid within the context of the
24 * currently running Worker which, when passed into `connect()` function from
25 * the "cloudflare:sockets" module, will connect to the Hyperdrive instance
26 * for your database.
27 */
28 readonly host: string;
29 /*
30 * The port that must be paired the the host field when connecting.
31 */
32 readonly port: number;
33 /*
34 * The username to use when authenticating to your database via Hyperdrive.
35 * Unlike the host and password, this will be the same every time
36 */
37 readonly user: string;
38 /*
39 * The randomly generated password to use when authenticating to your
40 * database via Hyperdrive. Like the host field, this password is only valid
41 * within the context of the currently running Worker instance from which
42 * it's read.
43 */
44 readonly password: string;
45 /*
46 * The name of the database to connect to.
47 */
48 readonly database: string;
49}