bun-types 1.3.2-canary.20251104T140728 → 1.3.2-canary.20251106T140813
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bun.d.ts +4 -4
- package/docs/README.md +28 -0
- package/globals.d.ts +0 -1
- package/overrides.d.ts +45 -15
- package/package.json +1 -1
- package/test.d.ts +1 -1
- package/docs/api/binary-data.md +0 -1038
- package/docs/api/cc.md +0 -197
- package/docs/api/color.md +0 -262
- package/docs/api/console.md +0 -57
- package/docs/api/cookie.md +0 -449
- package/docs/api/dns.md +0 -110
- package/docs/api/fetch.md +0 -463
- package/docs/api/ffi.md +0 -557
- package/docs/api/file-io.md +0 -366
- package/docs/api/file-system-router.md +0 -112
- package/docs/api/file.md +0 -19
- package/docs/api/glob.md +0 -178
- package/docs/api/globals.md +0 -387
- package/docs/api/hashing.md +0 -319
- package/docs/api/html-rewriter.md +0 -334
- package/docs/api/http.md +0 -1408
- package/docs/api/import-meta.md +0 -69
- package/docs/api/node-api.md +0 -14
- package/docs/api/redis.md +0 -597
- package/docs/api/s3.md +0 -850
- package/docs/api/secrets.md +0 -319
- package/docs/api/semver.md +0 -52
- package/docs/api/spawn.md +0 -582
- package/docs/api/sql.md +0 -1374
- package/docs/api/sqlite.md +0 -694
- package/docs/api/streams.md +0 -230
- package/docs/api/tcp.md +0 -221
- package/docs/api/transpiler.md +0 -276
- package/docs/api/udp.md +0 -123
- package/docs/api/utils.md +0 -891
- package/docs/api/websockets.md +0 -573
- package/docs/api/workers.md +0 -322
- package/docs/api/yaml.md +0 -668
- package/docs/benchmarks.md +0 -120
- package/docs/bun-flavored-toml.md +0 -42
- package/docs/bundler/css.md +0 -1028
- package/docs/bundler/css_modules.md +0 -145
- package/docs/bundler/executables.md +0 -626
- package/docs/bundler/fullstack.md +0 -418
- package/docs/bundler/hmr.md +0 -234
- package/docs/bundler/html.md +0 -349
- package/docs/bundler/index.md +0 -1735
- package/docs/bundler/intro.md +0 -75
- package/docs/bundler/loaders.md +0 -410
- package/docs/bundler/macros.md +0 -329
- package/docs/bundler/plugins.md +0 -449
- package/docs/bundler/vs-esbuild.md +0 -1127
- package/docs/cli/add.md +0 -173
- package/docs/cli/bun-completions.md +0 -3
- package/docs/cli/bun-create.md +0 -338
- package/docs/cli/bun-install.md +0 -349
- package/docs/cli/bun-upgrade.md +0 -39
- package/docs/cli/bunx.md +0 -89
- package/docs/cli/filter.md +0 -90
- package/docs/cli/info.md +0 -65
- package/docs/cli/init.md +0 -85
- package/docs/cli/install.md +0 -344
- package/docs/cli/link.md +0 -40
- package/docs/cli/outdated.md +0 -90
- package/docs/cli/patch-commit.md +0 -11
- package/docs/cli/pm.md +0 -285
- package/docs/cli/publish.md +0 -120
- package/docs/cli/remove.md +0 -7
- package/docs/cli/run.md +0 -261
- package/docs/cli/test.md +0 -397
- package/docs/cli/unlink.md +0 -9
- package/docs/cli/update.md +0 -129
- package/docs/cli/why.md +0 -67
- package/docs/contributing/upgrading-webkit.md +0 -57
- package/docs/ecosystem/elysia.md +0 -24
- package/docs/ecosystem/express.md +0 -37
- package/docs/ecosystem/hono.md +0 -18
- package/docs/ecosystem/react.md +0 -65
- package/docs/ecosystem/stric.md +0 -38
- package/docs/guides/binary/arraybuffer-to-array.md +0 -27
- package/docs/guides/binary/arraybuffer-to-blob.md +0 -24
- package/docs/guides/binary/arraybuffer-to-buffer.md +0 -25
- package/docs/guides/binary/arraybuffer-to-string.md +0 -15
- package/docs/guides/binary/arraybuffer-to-typedarray.md +0 -39
- package/docs/guides/binary/blob-to-arraybuffer.md +0 -14
- package/docs/guides/binary/blob-to-dataview.md +0 -14
- package/docs/guides/binary/blob-to-stream.md +0 -14
- package/docs/guides/binary/blob-to-string.md +0 -15
- package/docs/guides/binary/blob-to-typedarray.md +0 -14
- package/docs/guides/binary/buffer-to-arraybuffer.md +0 -14
- package/docs/guides/binary/buffer-to-blob.md +0 -14
- package/docs/guides/binary/buffer-to-readablestream.md +0 -41
- package/docs/guides/binary/buffer-to-string.md +0 -25
- package/docs/guides/binary/buffer-to-typedarray.md +0 -14
- package/docs/guides/binary/dataview-to-string.md +0 -15
- package/docs/guides/binary/typedarray-to-arraybuffer.md +0 -25
- package/docs/guides/binary/typedarray-to-blob.md +0 -16
- package/docs/guides/binary/typedarray-to-buffer.md +0 -14
- package/docs/guides/binary/typedarray-to-dataview.md +0 -14
- package/docs/guides/binary/typedarray-to-readablestream.md +0 -41
- package/docs/guides/binary/typedarray-to-string.md +0 -16
- package/docs/guides/deployment/railway.md +0 -157
- package/docs/guides/ecosystem/astro.md +0 -72
- package/docs/guides/ecosystem/discordjs.md +0 -77
- package/docs/guides/ecosystem/docker.md +0 -140
- package/docs/guides/ecosystem/drizzle.md +0 -185
- package/docs/guides/ecosystem/edgedb.md +0 -228
- package/docs/guides/ecosystem/elysia.md +0 -31
- package/docs/guides/ecosystem/express.md +0 -40
- package/docs/guides/ecosystem/hono.md +0 -39
- package/docs/guides/ecosystem/mongoose.md +0 -87
- package/docs/guides/ecosystem/neon-drizzle.md +0 -220
- package/docs/guides/ecosystem/neon-serverless-postgres.md +0 -55
- package/docs/guides/ecosystem/nextjs.md +0 -49
- package/docs/guides/ecosystem/nuxt.md +0 -56
- package/docs/guides/ecosystem/pm2.md +0 -57
- package/docs/guides/ecosystem/prisma.md +0 -141
- package/docs/guides/ecosystem/qwik.md +0 -107
- package/docs/guides/ecosystem/react.md +0 -50
- package/docs/guides/ecosystem/remix.md +0 -78
- package/docs/guides/ecosystem/render.md +0 -79
- package/docs/guides/ecosystem/sentry.md +0 -52
- package/docs/guides/ecosystem/solidstart.md +0 -58
- package/docs/guides/ecosystem/ssr-react.md +0 -51
- package/docs/guides/ecosystem/stric.md +0 -55
- package/docs/guides/ecosystem/sveltekit.md +0 -125
- package/docs/guides/ecosystem/systemd.md +0 -113
- package/docs/guides/ecosystem/vite.md +0 -71
- package/docs/guides/html-rewriter/extract-links.md +0 -68
- package/docs/guides/html-rewriter/extract-social-meta.md +0 -93
- package/docs/guides/http/cluster.md +0 -66
- package/docs/guides/http/fetch-unix.md +0 -33
- package/docs/guides/http/fetch.md +0 -24
- package/docs/guides/http/file-uploads.md +0 -94
- package/docs/guides/http/hot.md +0 -26
- package/docs/guides/http/proxy.md +0 -24
- package/docs/guides/http/server.md +0 -46
- package/docs/guides/http/simple.md +0 -18
- package/docs/guides/http/stream-file.md +0 -48
- package/docs/guides/http/stream-iterator.md +0 -47
- package/docs/guides/http/stream-node-streams-in-bun.md +0 -20
- package/docs/guides/http/tls.md +0 -30
- package/docs/guides/install/add-dev.md +0 -26
- package/docs/guides/install/add-git.md +0 -36
- package/docs/guides/install/add-optional.md +0 -25
- package/docs/guides/install/add-peer.md +0 -43
- package/docs/guides/install/add-tarball.md +0 -33
- package/docs/guides/install/add.md +0 -42
- package/docs/guides/install/azure-artifacts.md +0 -73
- package/docs/guides/install/cicd.md +0 -41
- package/docs/guides/install/custom-registry.md +0 -30
- package/docs/guides/install/from-npm-install-to-bun-install.md +0 -214
- package/docs/guides/install/git-diff-bun-lockfile.md +0 -44
- package/docs/guides/install/jfrog-artifactory.md +0 -28
- package/docs/guides/install/npm-alias.md +0 -23
- package/docs/guides/install/registry-scope.md +0 -38
- package/docs/guides/install/trusted.md +0 -46
- package/docs/guides/install/workspaces.md +0 -70
- package/docs/guides/install/yarnlock.md +0 -44
- package/docs/guides/process/argv.md +0 -58
- package/docs/guides/process/ctrl-c.md +0 -16
- package/docs/guides/process/ipc.md +0 -66
- package/docs/guides/process/nanoseconds.md +0 -13
- package/docs/guides/process/os-signals.md +0 -39
- package/docs/guides/process/spawn-stderr.md +0 -31
- package/docs/guides/process/spawn-stdout.md +0 -26
- package/docs/guides/process/spawn.md +0 -41
- package/docs/guides/process/stdin.md +0 -54
- package/docs/guides/read-file/arraybuffer.md +0 -28
- package/docs/guides/read-file/buffer.md +0 -19
- package/docs/guides/read-file/exists.md +0 -16
- package/docs/guides/read-file/json.md +0 -17
- package/docs/guides/read-file/mime.md +0 -20
- package/docs/guides/read-file/stream.md +0 -26
- package/docs/guides/read-file/string.md +0 -22
- package/docs/guides/read-file/uint8array.md +0 -21
- package/docs/guides/read-file/watch.md +0 -68
- package/docs/guides/runtime/build-time-constants.md +0 -293
- package/docs/guides/runtime/cicd.md +0 -43
- package/docs/guides/runtime/codesign-macos-executable.md +0 -56
- package/docs/guides/runtime/define-constant.md +0 -145
- package/docs/guides/runtime/delete-directory.md +0 -37
- package/docs/guides/runtime/delete-file.md +0 -19
- package/docs/guides/runtime/heap-snapshot.md +0 -26
- package/docs/guides/runtime/import-html.md +0 -15
- package/docs/guides/runtime/import-json.md +0 -44
- package/docs/guides/runtime/import-toml.md +0 -30
- package/docs/guides/runtime/import-yaml.md +0 -102
- package/docs/guides/runtime/read-env.md +0 -32
- package/docs/guides/runtime/set-env.md +0 -47
- package/docs/guides/runtime/shell.md +0 -40
- package/docs/guides/runtime/timezone.md +0 -35
- package/docs/guides/runtime/tsconfig-paths.md +0 -29
- package/docs/guides/runtime/typescript.md +0 -49
- package/docs/guides/runtime/vscode-debugger.md +0 -47
- package/docs/guides/runtime/web-debugger.md +0 -82
- package/docs/guides/streams/node-readable-to-arraybuffer.md +0 -11
- package/docs/guides/streams/node-readable-to-blob.md +0 -11
- package/docs/guides/streams/node-readable-to-json.md +0 -12
- package/docs/guides/streams/node-readable-to-string.md +0 -12
- package/docs/guides/streams/node-readable-to-uint8array.md +0 -11
- package/docs/guides/streams/to-array.md +0 -14
- package/docs/guides/streams/to-arraybuffer.md +0 -14
- package/docs/guides/streams/to-blob.md +0 -14
- package/docs/guides/streams/to-buffer.md +0 -15
- package/docs/guides/streams/to-json.md +0 -14
- package/docs/guides/streams/to-string.md +0 -14
- package/docs/guides/streams/to-typedarray.md +0 -22
- package/docs/guides/test/bail.md +0 -22
- package/docs/guides/test/coverage-threshold.md +0 -60
- package/docs/guides/test/coverage.md +0 -44
- package/docs/guides/test/happy-dom.md +0 -68
- package/docs/guides/test/migrate-from-jest.md +0 -143
- package/docs/guides/test/mock-clock.md +0 -48
- package/docs/guides/test/mock-functions.md +0 -68
- package/docs/guides/test/rerun-each.md +0 -14
- package/docs/guides/test/run-tests.md +0 -111
- package/docs/guides/test/skip-tests.md +0 -39
- package/docs/guides/test/snapshot.md +0 -95
- package/docs/guides/test/spy-on.md +0 -46
- package/docs/guides/test/svelte-test.md +0 -120
- package/docs/guides/test/testing-library.md +0 -92
- package/docs/guides/test/timeout.md +0 -15
- package/docs/guides/test/todo-tests.md +0 -67
- package/docs/guides/test/update-snapshots.md +0 -46
- package/docs/guides/test/watch-mode.md +0 -19
- package/docs/guides/util/base64.md +0 -15
- package/docs/guides/util/deep-equals.md +0 -39
- package/docs/guides/util/deflate.md +0 -18
- package/docs/guides/util/detect-bun.md +0 -23
- package/docs/guides/util/entrypoint.md +0 -17
- package/docs/guides/util/escape-html.md +0 -22
- package/docs/guides/util/file-url-to-path.md +0 -14
- package/docs/guides/util/gzip.md +0 -18
- package/docs/guides/util/hash-a-password.md +0 -54
- package/docs/guides/util/import-meta-dir.md +0 -13
- package/docs/guides/util/import-meta-file.md +0 -13
- package/docs/guides/util/import-meta-path.md +0 -13
- package/docs/guides/util/javascript-uuid.md +0 -23
- package/docs/guides/util/main.md +0 -32
- package/docs/guides/util/path-to-file-url.md +0 -14
- package/docs/guides/util/sleep.md +0 -22
- package/docs/guides/util/version.md +0 -21
- package/docs/guides/util/which-path-to-executable-bin.md +0 -15
- package/docs/guides/websocket/compression.md +0 -31
- package/docs/guides/websocket/context.md +0 -77
- package/docs/guides/websocket/pubsub.md +0 -41
- package/docs/guides/websocket/simple.md +0 -33
- package/docs/guides/write-file/append.md +0 -52
- package/docs/guides/write-file/basic.md +0 -44
- package/docs/guides/write-file/blob.md +0 -28
- package/docs/guides/write-file/cat.md +0 -17
- package/docs/guides/write-file/file-cp.md +0 -16
- package/docs/guides/write-file/filesink.md +0 -52
- package/docs/guides/write-file/response.md +0 -17
- package/docs/guides/write-file/stdout.md +0 -21
- package/docs/guides/write-file/stream.md +0 -17
- package/docs/guides/write-file/unlink.md +0 -16
- package/docs/index.md +0 -77
- package/docs/install/audit.md +0 -57
- package/docs/install/cache.md +0 -59
- package/docs/install/catalogs.md +0 -298
- package/docs/install/index.md +0 -248
- package/docs/install/isolated.md +0 -197
- package/docs/install/lifecycle.md +0 -46
- package/docs/install/lockfile.md +0 -58
- package/docs/install/npmrc.md +0 -105
- package/docs/install/overrides.md +0 -73
- package/docs/install/patch.md +0 -59
- package/docs/install/registries.md +0 -30
- package/docs/install/security-scanner-api.md +0 -81
- package/docs/install/workspaces.md +0 -114
- package/docs/installation.md +0 -327
- package/docs/project/asan.md +0 -124
- package/docs/project/benchmarking.md +0 -203
- package/docs/project/bindgen.md +0 -225
- package/docs/project/building-windows.md +0 -162
- package/docs/project/contributing.md +0 -347
- package/docs/project/internals/build-process-for-ci.md +0 -75
- package/docs/project/licensing.md +0 -73
- package/docs/project/roadmap.md +0 -87
- package/docs/quickstart.md +0 -157
- package/docs/runtime/autoimport.md +0 -94
- package/docs/runtime/bun-apis.md +0 -207
- package/docs/runtime/bunfig.md +0 -772
- package/docs/runtime/debugger.md +0 -325
- package/docs/runtime/env.md +0 -253
- package/docs/runtime/hot.md +0 -145
- package/docs/runtime/index.md +0 -312
- package/docs/runtime/jsx.md +0 -385
- package/docs/runtime/loaders.md +0 -130
- package/docs/runtime/modules.md +0 -320
- package/docs/runtime/nodejs-apis.md +0 -463
- package/docs/runtime/plugins.md +0 -561
- package/docs/runtime/shell.md +0 -605
- package/docs/runtime/typescript.md +0 -139
- package/docs/runtime/web-apis.md +0 -128
- package/docs/test/configuration.md +0 -154
- package/docs/test/coverage.md +0 -142
- package/docs/test/discovery.md +0 -85
- package/docs/test/dom.md +0 -75
- package/docs/test/examples/concurrent-test-glob.md +0 -132
- package/docs/test/hot.md +0 -15
- package/docs/test/lifecycle.md +0 -81
- package/docs/test/mocks.md +0 -313
- package/docs/test/reporters.md +0 -117
- package/docs/test/runtime-behavior.md +0 -95
- package/docs/test/snapshots.md +0 -68
- package/docs/test/time.md +0 -126
- package/docs/test/writing.md +0 -825
- package/docs/typescript.md +0 -53
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Use EdgeDB with Bun
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
EdgeDB is a graph-relational database powered by Postgres under the hood. It provides a declarative schema language, migrations system, and object-oriented query language, in addition to supporting raw SQL queries. It solves the object-relational mapping problem at the database layer, eliminating the need for an ORM library in your application code.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
First, [install EdgeDB](https://www.edgedb.com/install) if you haven't already.
|
|
10
|
-
|
|
11
|
-
{% codetabs %}
|
|
12
|
-
|
|
13
|
-
```sh#Linux/macOS
|
|
14
|
-
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.edgedb.com | sh
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
```sh#Windows
|
|
18
|
-
$ iwr https://ps1.edgedb.com -useb | iex
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
{% /codetabs %}
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
Use `bun init` to create a fresh project.
|
|
26
|
-
|
|
27
|
-
```sh
|
|
28
|
-
$ mkdir my-edgedb-app
|
|
29
|
-
$ cd my-edgedb-app
|
|
30
|
-
$ bun init -y
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
We'll use the EdgeDB CLI to initialize an EdgeDB instance for our project. This creates an `edgedb.toml` file in our project root.
|
|
36
|
-
|
|
37
|
-
```sh
|
|
38
|
-
$ edgedb project init
|
|
39
|
-
No `edgedb.toml` found in `/Users/colinmcd94/Documents/bun/fun/examples/my-edgedb-app` or above
|
|
40
|
-
Do you want to initialize a new project? [Y/n]
|
|
41
|
-
> Y
|
|
42
|
-
Specify the name of EdgeDB instance to use with this project [default: my_edgedb_app]:
|
|
43
|
-
> my_edgedb_app
|
|
44
|
-
Checking EdgeDB versions...
|
|
45
|
-
Specify the version of EdgeDB to use with this project [default: x.y]:
|
|
46
|
-
> x.y
|
|
47
|
-
┌─────────────────────┬────────────────────────────────────────────────────────────────────────┐
|
|
48
|
-
│ Project directory │ /Users/colinmcd94/Documents/bun/fun/examples/my-edgedb-app │
|
|
49
|
-
│ Project config │ /Users/colinmcd94/Documents/bun/fun/examples/my-edgedb-app/edgedb.toml │
|
|
50
|
-
│ Schema dir (empty) │ /Users/colinmcd94/Documents/bun/fun/examples/my-edgedb-app/dbschema │
|
|
51
|
-
│ Installation method │ portable package │
|
|
52
|
-
│ Version │ x.y+6d5921b │
|
|
53
|
-
│ Instance name │ my_edgedb_app │
|
|
54
|
-
└─────────────────────┴────────────────────────────────────────────────────────────────────────┘
|
|
55
|
-
Version x.y+6d5921b is already downloaded
|
|
56
|
-
Initializing EdgeDB instance...
|
|
57
|
-
Applying migrations...
|
|
58
|
-
Everything is up to date. Revision initial
|
|
59
|
-
Project initialized.
|
|
60
|
-
To connect to my_edgedb_app, run `edgedb`
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
---
|
|
64
|
-
|
|
65
|
-
To see if the database is running, let's open a REPL and run a simple query.
|
|
66
|
-
|
|
67
|
-
Then run `\quit` to exit the REPL.
|
|
68
|
-
|
|
69
|
-
```sh
|
|
70
|
-
$ edgedb
|
|
71
|
-
edgedb> select 1 + 1;
|
|
72
|
-
2
|
|
73
|
-
edgedb> \quit
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
---
|
|
77
|
-
|
|
78
|
-
With the project initialized, we can define a schema. The `edgedb project init` command already created a `dbschema/default.esdl` file to contain our schema.
|
|
79
|
-
|
|
80
|
-
```txt
|
|
81
|
-
dbschema
|
|
82
|
-
├── default.esdl
|
|
83
|
-
└── migrations
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
---
|
|
87
|
-
|
|
88
|
-
Open that file and paste the following contents.
|
|
89
|
-
|
|
90
|
-
```txt
|
|
91
|
-
module default {
|
|
92
|
-
type Movie {
|
|
93
|
-
required title: str;
|
|
94
|
-
releaseYear: int64;
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
---
|
|
100
|
-
|
|
101
|
-
Then generate and apply an initial migration.
|
|
102
|
-
|
|
103
|
-
```sh
|
|
104
|
-
$ edgedb migration create
|
|
105
|
-
Created /Users/colinmcd94/Documents/bun/fun/examples/my-edgedb-app/dbschema/migrations/00001.edgeql, id: m1uwekrn4ni4qs7ul7hfar4xemm5kkxlpswolcoyqj3xdhweomwjrq
|
|
106
|
-
$ edgedb migrate
|
|
107
|
-
Applied m1uwekrn4ni4qs7ul7hfar4xemm5kkxlpswolcoyqj3xdhweomwjrq (00001.edgeql)
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
With our schema applied, let's execute some queries using EdgeDB's JavaScript client library. We'll install the client library and EdgeDB's codegen CLI, and create a `seed.ts`.file.
|
|
113
|
-
|
|
114
|
-
```sh
|
|
115
|
-
$ bun add edgedb
|
|
116
|
-
$ bun add -D @edgedb/generate
|
|
117
|
-
$ touch seed.ts
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
---
|
|
121
|
-
|
|
122
|
-
Paste the following code into `seed.ts`.
|
|
123
|
-
|
|
124
|
-
The client auto-connects to the database. We insert a couple movies using the `.execute()` method. We will use EdgeQL's `for` expression to turn this bulk insert into a single optimized query.
|
|
125
|
-
|
|
126
|
-
```ts
|
|
127
|
-
import { createClient } from "edgedb";
|
|
128
|
-
|
|
129
|
-
const client = createClient();
|
|
130
|
-
|
|
131
|
-
const INSERT_MOVIE = `
|
|
132
|
-
with movies := <array<tuple<title: str, year: int64>>>$movies
|
|
133
|
-
for movie in array_unpack(movies) union (
|
|
134
|
-
insert Movie {
|
|
135
|
-
title := movie.title,
|
|
136
|
-
releaseYear := movie.year,
|
|
137
|
-
}
|
|
138
|
-
)
|
|
139
|
-
`;
|
|
140
|
-
|
|
141
|
-
const movies = [
|
|
142
|
-
{ title: "The Matrix", year: 1999 },
|
|
143
|
-
{ title: "The Matrix Reloaded", year: 2003 },
|
|
144
|
-
{ title: "The Matrix Revolutions", year: 2003 },
|
|
145
|
-
];
|
|
146
|
-
|
|
147
|
-
await client.execute(INSERT_MOVIE, { movies });
|
|
148
|
-
|
|
149
|
-
console.log(`Seeding complete.`);
|
|
150
|
-
process.exit();
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
---
|
|
154
|
-
|
|
155
|
-
Then run this file with Bun.
|
|
156
|
-
|
|
157
|
-
```sh
|
|
158
|
-
$ bun run seed.ts
|
|
159
|
-
Seeding complete.
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
---
|
|
163
|
-
|
|
164
|
-
EdgeDB implements a number of code generation tools for TypeScript. To query our newly seeded database in a typesafe way, we'll use `@edgedb/generate` to code-generate the EdgeQL query builder.
|
|
165
|
-
|
|
166
|
-
```sh
|
|
167
|
-
$ bunx @edgedb/generate edgeql-js
|
|
168
|
-
Generating query builder...
|
|
169
|
-
Detected tsconfig.json, generating TypeScript files.
|
|
170
|
-
To override this, use the --target flag.
|
|
171
|
-
Run `npx @edgedb/generate --help` for full options.
|
|
172
|
-
Introspecting database schema...
|
|
173
|
-
Writing files to ./dbschema/edgeql-js
|
|
174
|
-
Generation complete! 🤘
|
|
175
|
-
Checking the generated query builder into version control
|
|
176
|
-
is not recommended. Would you like to update .gitignore to ignore
|
|
177
|
-
the query builder directory? The following line will be added:
|
|
178
|
-
|
|
179
|
-
dbschema/edgeql-js
|
|
180
|
-
|
|
181
|
-
[y/n] (leave blank for "y")
|
|
182
|
-
> y
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
---
|
|
186
|
-
|
|
187
|
-
In `index.ts`, we can import the generated query builder from `./dbschema/edgeql-js` and write a simple select query.
|
|
188
|
-
|
|
189
|
-
```ts
|
|
190
|
-
import { createClient } from "edgedb";
|
|
191
|
-
import e from "./dbschema/edgeql-js";
|
|
192
|
-
|
|
193
|
-
const client = createClient();
|
|
194
|
-
|
|
195
|
-
const query = e.select(e.Movie, () => ({
|
|
196
|
-
title: true,
|
|
197
|
-
releaseYear: true,
|
|
198
|
-
}));
|
|
199
|
-
|
|
200
|
-
const results = await query.run(client);
|
|
201
|
-
console.log(results);
|
|
202
|
-
|
|
203
|
-
results; // { title: string, releaseYear: number | null }[]
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
---
|
|
207
|
-
|
|
208
|
-
Running the file with Bun, we can see the list of movies we inserted.
|
|
209
|
-
|
|
210
|
-
```sh
|
|
211
|
-
$ bun run index.ts
|
|
212
|
-
[
|
|
213
|
-
{
|
|
214
|
-
title: "The Matrix",
|
|
215
|
-
releaseYear: 1999
|
|
216
|
-
}, {
|
|
217
|
-
title: "The Matrix Reloaded",
|
|
218
|
-
releaseYear: 2003
|
|
219
|
-
}, {
|
|
220
|
-
title: "The Matrix Revolutions",
|
|
221
|
-
releaseYear: 2003
|
|
222
|
-
}
|
|
223
|
-
]
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
---
|
|
227
|
-
|
|
228
|
-
For complete documentation, refer to the [EdgeDB docs](https://www.edgedb.com/docs).
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Build an HTTP server using Elysia and Bun
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
[Elysia](https://elysiajs.com) is a Bun-first performance focused web framework that takes full advantage of Bun's HTTP, file system, and hot reloading APIs. Get started with `bun create`.
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
$ bun create elysia myapp
|
|
9
|
-
$ cd myapp
|
|
10
|
-
$ bun run dev
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
To define a simple HTTP route and start a server with Elysia:
|
|
16
|
-
|
|
17
|
-
```ts#server.ts
|
|
18
|
-
import { Elysia } from 'elysia'
|
|
19
|
-
|
|
20
|
-
const app = new Elysia()
|
|
21
|
-
.get('/', () => 'Hello Elysia')
|
|
22
|
-
.listen(8080)
|
|
23
|
-
|
|
24
|
-
console.log(`🦊 Elysia is running at on port ${app.server?.port}...`)
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
Elysia is a full-featured server framework with Express-like syntax, type inference, middleware, file uploads, and plugins for JWT authentication, tRPC, and more. It's also is one of the [fastest Bun web frameworks](https://github.com/SaltyAom/bun-http-framework-benchmark).
|
|
30
|
-
|
|
31
|
-
Refer to the Elysia [documentation](https://elysiajs.com/quick-start.html) for more information.
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Build an HTTP server using Express and Bun
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Express and other major Node.js HTTP libraries should work out of the box. Bun implements the [`node:http`](https://nodejs.org/api/http.html) and [`node:https`](https://nodejs.org/api/https.html) modules that these libraries rely on.
|
|
6
|
-
|
|
7
|
-
{% callout %}
|
|
8
|
-
Refer to the [Runtime > Node.js APIs](https://bun.com/docs/runtime/nodejs-apis#node-http) page for more detailed compatibility information.
|
|
9
|
-
{% /callout %}
|
|
10
|
-
|
|
11
|
-
```sh
|
|
12
|
-
$ bun add express
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
To define a simple HTTP route and start a server with Express:
|
|
18
|
-
|
|
19
|
-
```ts#server.ts
|
|
20
|
-
import express from "express";
|
|
21
|
-
|
|
22
|
-
const app = express();
|
|
23
|
-
const port = 8080;
|
|
24
|
-
|
|
25
|
-
app.get("/", (req, res) => {
|
|
26
|
-
res.send("Hello World!");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
app.listen(port, () => {
|
|
30
|
-
console.log(`Listening on port ${port}...`);
|
|
31
|
-
});
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
To start the server on `localhost`:
|
|
37
|
-
|
|
38
|
-
```sh
|
|
39
|
-
$ bun server.ts
|
|
40
|
-
```
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Build an HTTP server using Hono and Bun
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
[Hono](https://github.com/honojs/hono) is a lightweight ultrafast web framework designed for the edge.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { Hono } from "hono";
|
|
9
|
-
const app = new Hono();
|
|
10
|
-
|
|
11
|
-
app.get("/", c => c.text("Hono!"));
|
|
12
|
-
|
|
13
|
-
export default app;
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
Use `create-hono` to get started with one of Hono's project templates. Select `bun` when prompted for a template.
|
|
19
|
-
|
|
20
|
-
```sh
|
|
21
|
-
$ bun create hono myapp
|
|
22
|
-
✔ Which template do you want to use? › bun
|
|
23
|
-
cloned honojs/starter#main to /path/to/myapp
|
|
24
|
-
✔ Copied project files
|
|
25
|
-
$ cd myapp
|
|
26
|
-
$ bun install
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
Then start the dev server and visit [localhost:3000](http://localhost:3000).
|
|
32
|
-
|
|
33
|
-
```sh
|
|
34
|
-
$ bun run dev
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
---
|
|
38
|
-
|
|
39
|
-
Refer to Hono's guide on [getting started with Bun](https://hono.dev/getting-started/bun) for more information.
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Read and write data to MongoDB using Mongoose and Bun
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
MongoDB and Mongoose work out of the box with Bun. This guide assumes you've already installed MongoDB and are running it as background process/service on your development machine. Follow [this guide](https://www.mongodb.com/docs/manual/installation/) for details.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
Once MongoDB is running, create a directory and initialize it with `bun init`.
|
|
10
|
-
|
|
11
|
-
```sh
|
|
12
|
-
$ mkdir mongoose-app
|
|
13
|
-
$ cd mongoose-app
|
|
14
|
-
$ bun init
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
Then add Mongoose as a dependency.
|
|
20
|
-
|
|
21
|
-
```sh
|
|
22
|
-
$ bun add mongoose
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
In `schema.ts` we'll declare and export a simple `Animal` model.
|
|
28
|
-
|
|
29
|
-
```ts#schema.ts
|
|
30
|
-
import * as mongoose from 'mongoose';
|
|
31
|
-
|
|
32
|
-
const animalSchema = new mongoose.Schema(
|
|
33
|
-
{
|
|
34
|
-
name: {type: String, required: true},
|
|
35
|
-
sound: {type: String, required: true},
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
methods: {
|
|
39
|
-
speak() {
|
|
40
|
-
console.log(`${this.sound}!`);
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
export type Animal = mongoose.InferSchemaType<typeof animalSchema>;
|
|
47
|
-
export const Animal = mongoose.model('Animal', animalSchema);
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
|
|
52
|
-
Now from `index.ts` we can import `Animal`, connect to MongoDB, and add some data to our database.
|
|
53
|
-
|
|
54
|
-
```ts#index.ts
|
|
55
|
-
import * as mongoose from 'mongoose';
|
|
56
|
-
import {Animal} from './schema';
|
|
57
|
-
|
|
58
|
-
// connect to database
|
|
59
|
-
await mongoose.connect('mongodb://127.0.0.1:27017/mongoose-app');
|
|
60
|
-
|
|
61
|
-
// create new Animal
|
|
62
|
-
const cow = new Animal({
|
|
63
|
-
name: 'Cow',
|
|
64
|
-
sound: 'Moo',
|
|
65
|
-
});
|
|
66
|
-
await cow.save(); // saves to the database
|
|
67
|
-
|
|
68
|
-
// read all Animals
|
|
69
|
-
const animals = await Animal.find();
|
|
70
|
-
animals[0].speak(); // logs "Moo!"
|
|
71
|
-
|
|
72
|
-
// disconnect
|
|
73
|
-
await mongoose.disconnect();
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
---
|
|
77
|
-
|
|
78
|
-
Let's run this with `bun run`.
|
|
79
|
-
|
|
80
|
-
```bash
|
|
81
|
-
$ bun run index.ts
|
|
82
|
-
Moo!
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
---
|
|
86
|
-
|
|
87
|
-
This is a simple introduction to using Mongoose with TypeScript and Bun. As you build your application, refer to the official [MongoDB](https://docs.mongodb.com/) and [Mongoose](https://mongoosejs.com/docs/) sites for complete documentation.
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Use Neon Postgres through Drizzle ORM
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
[Neon](https://neon.tech/) is a fully managed serverless Postgres, separating compute and storage to offer features like autoscaling, branching and bottomless storage. Neon can be used from Bun directly using the `@neondatabase/serverless` driver or through an ORM like `Drizzle`.
|
|
6
|
-
|
|
7
|
-
Drizzle ORM supports both a SQL-like "query builder" API and an ORM-like [Queries API](https://orm.drizzle.team/docs/rqb). Get started by creating a project directory, initializing the directory using `bun init`, and installing Drizzle and the [Neon serverless driver](https://github.com/neondatabase/serverless/).
|
|
8
|
-
|
|
9
|
-
```sh
|
|
10
|
-
$ mkdir bun-drizzle-neon
|
|
11
|
-
$ cd bun-drizzle-neon
|
|
12
|
-
$ bun init -y
|
|
13
|
-
$ bun add drizzle-orm @neondatabase/serverless
|
|
14
|
-
$ bun add -D drizzle-kit
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
Create a `.env.local` file and add your [Neon Postgres connection string](https://neon.tech/docs/connect/connect-from-any-app) to it.
|
|
20
|
-
|
|
21
|
-
```sh
|
|
22
|
-
DATABASE_URL=postgresql://username:password@ep-adj-noun-guid.us-east-1.aws.neon.tech/neondb?sslmode=require
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
We will connect to the Neon database using the Neon serverless driver, wrapped in a Drizzle database instance.
|
|
28
|
-
|
|
29
|
-
```ts#db.ts
|
|
30
|
-
import { neon } from '@neondatabase/serverless';
|
|
31
|
-
import { drizzle } from 'drizzle-orm/neon-http';
|
|
32
|
-
|
|
33
|
-
// Bun automatically loads the DATABASE_URL from .env.local
|
|
34
|
-
// Refer to: https://bun.com/docs/runtime/env for more information
|
|
35
|
-
const sql = neon(process.env.DATABASE_URL!);
|
|
36
|
-
|
|
37
|
-
export const db = drizzle(sql);
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
---
|
|
41
|
-
|
|
42
|
-
To see the database in action, add these lines to `index.ts`.
|
|
43
|
-
|
|
44
|
-
```ts#index.ts
|
|
45
|
-
import { db } from "./db";
|
|
46
|
-
import { sql } from "drizzle-orm";
|
|
47
|
-
|
|
48
|
-
const query = sql`select 'hello world' as text`;
|
|
49
|
-
const result = await db.execute(query);
|
|
50
|
-
console.log(result.rows);
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
---
|
|
54
|
-
|
|
55
|
-
Then run `index.ts` with Bun.
|
|
56
|
-
|
|
57
|
-
```sh
|
|
58
|
-
$ bun run index.ts
|
|
59
|
-
[
|
|
60
|
-
{
|
|
61
|
-
text: "hello world",
|
|
62
|
-
}
|
|
63
|
-
]
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
We can define a schema for our database using Drizzle ORM primitives. Create a `schema.ts` file and add this code.
|
|
69
|
-
|
|
70
|
-
```ts#schema.ts
|
|
71
|
-
import { pgTable, integer, serial, text, timestamp } from "drizzle-orm/pg-core";
|
|
72
|
-
|
|
73
|
-
export const authors = pgTable("authors", {
|
|
74
|
-
id: serial("id").primaryKey(),
|
|
75
|
-
name: text("name").notNull(),
|
|
76
|
-
bio: text("bio"),
|
|
77
|
-
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
78
|
-
});
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
---
|
|
82
|
-
|
|
83
|
-
We then use the `drizzle-kit` CLI to generate an initial SQL migration.
|
|
84
|
-
|
|
85
|
-
```sh
|
|
86
|
-
$ bunx drizzle-kit generate --dialect postgresql --schema ./schema.ts --out ./drizzle
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
---
|
|
90
|
-
|
|
91
|
-
This creates a new `drizzle` directory containing a `.sql` migration file and `meta` directory.
|
|
92
|
-
|
|
93
|
-
```txt
|
|
94
|
-
drizzle
|
|
95
|
-
├── 0000_aspiring_post.sql
|
|
96
|
-
└── meta
|
|
97
|
-
├── 0000_snapshot.json
|
|
98
|
-
└── _journal.json
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
---
|
|
102
|
-
|
|
103
|
-
We can execute these migrations with a simple `migrate.ts` script. This script creates a new connection to the Neon database and executes all unexecuted migrations in the `drizzle` directory.
|
|
104
|
-
|
|
105
|
-
```ts#migrate.ts
|
|
106
|
-
import { db } from './db';
|
|
107
|
-
import { migrate } from "drizzle-orm/neon-http/migrator";
|
|
108
|
-
|
|
109
|
-
const main = async () => {
|
|
110
|
-
try {
|
|
111
|
-
await migrate(db, { migrationsFolder: "drizzle" });
|
|
112
|
-
console.log("Migration completed");
|
|
113
|
-
} catch (error) {
|
|
114
|
-
console.error("Error during migration:", error);
|
|
115
|
-
process.exit(1);
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
main();
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
---
|
|
123
|
-
|
|
124
|
-
We can run this script with `bun` to execute the migration.
|
|
125
|
-
|
|
126
|
-
```sh
|
|
127
|
-
$ bun run migrate.ts
|
|
128
|
-
Migration completed
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
---
|
|
132
|
-
|
|
133
|
-
We can now add some data to our database. Create a `seed.ts` file with the following contents.
|
|
134
|
-
|
|
135
|
-
```ts#seed.ts
|
|
136
|
-
import { db } from "./db";
|
|
137
|
-
import * as schema from "./schema";
|
|
138
|
-
|
|
139
|
-
async function seed() {
|
|
140
|
-
await db.insert(schema.authors).values([
|
|
141
|
-
{
|
|
142
|
-
name: "J.R.R. Tolkien",
|
|
143
|
-
bio: "The creator of Middle-earth and author of The Lord of the Rings.",
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
name: "George R.R. Martin",
|
|
147
|
-
bio: "The author of the epic fantasy series A Song of Ice and Fire.",
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
name: "J.K. Rowling",
|
|
151
|
-
bio: "The creator of the Harry Potter series.",
|
|
152
|
-
},
|
|
153
|
-
]);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
async function main() {
|
|
157
|
-
try {
|
|
158
|
-
await seed();
|
|
159
|
-
console.log("Seeding completed");
|
|
160
|
-
} catch (error) {
|
|
161
|
-
console.error("Error during seeding:", error);
|
|
162
|
-
process.exit(1);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
main();
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
---
|
|
170
|
-
|
|
171
|
-
Then run this file.
|
|
172
|
-
|
|
173
|
-
```sh
|
|
174
|
-
$ bun run seed.ts
|
|
175
|
-
Seeding completed
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
---
|
|
179
|
-
|
|
180
|
-
We now have a database with a schema and sample data. We can use Drizzle to query it. Replace the contents of `index.ts` with the following.
|
|
181
|
-
|
|
182
|
-
```ts#index.ts
|
|
183
|
-
import * as schema from "./schema";
|
|
184
|
-
import { db } from "./db";
|
|
185
|
-
|
|
186
|
-
const result = await db.select().from(schema.authors);
|
|
187
|
-
console.log(result);
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
---
|
|
191
|
-
|
|
192
|
-
Then run the file. You should see the three authors we inserted.
|
|
193
|
-
|
|
194
|
-
```sh
|
|
195
|
-
$ bun run index.ts
|
|
196
|
-
[
|
|
197
|
-
{
|
|
198
|
-
id: 1,
|
|
199
|
-
name: "J.R.R. Tolkien",
|
|
200
|
-
bio: "The creator of Middle-earth and author of The Lord of the Rings.",
|
|
201
|
-
createdAt: 2024-05-11T10:28:46.029Z,
|
|
202
|
-
}, {
|
|
203
|
-
id: 2,
|
|
204
|
-
name: "George R.R. Martin",
|
|
205
|
-
bio: "The author of the epic fantasy series A Song of Ice and Fire.",
|
|
206
|
-
createdAt: 2024-05-11T10:28:46.029Z,
|
|
207
|
-
}, {
|
|
208
|
-
id: 3,
|
|
209
|
-
name: "J.K. Rowling",
|
|
210
|
-
bio: "The creator of the Harry Potter series.",
|
|
211
|
-
createdAt: 2024-05-11T10:28:46.029Z,
|
|
212
|
-
}
|
|
213
|
-
]
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
---
|
|
217
|
-
|
|
218
|
-
This example used the Neon serverless driver's SQL-over-HTTP functionality. Neon's serverless driver also exposes `Client` and `Pool` constructors to enable sessions, interactive transactions, and node-postgres compatibility. Refer to [Neon's documentation](https://neon.tech/docs/serverless/serverless-driver) for a complete overview.
|
|
219
|
-
|
|
220
|
-
Refer to the [Drizzle website](https://orm.drizzle.team/docs/overview) for more documentation on using the Drizzle ORM.
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Use Neon's Serverless Postgres with Bun
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
[Neon](https://neon.tech/) is a fully managed serverless Postgres. Neon separates compute and storage to offer modern developer features such as autoscaling, branching, bottomless storage, and more.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
Get started by creating a project directory, initializing the directory using `bun init`, and adding the [Neon serverless driver](https://github.com/neondatabase/serverless/) as a project dependency.
|
|
10
|
-
|
|
11
|
-
```sh
|
|
12
|
-
$ mkdir bun-neon-postgres
|
|
13
|
-
$ cd bun-neon-postgres
|
|
14
|
-
$ bun init -y
|
|
15
|
-
$ bun add @neondatabase/serverless
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
Create a `.env.local` file and add your [Neon Postgres connection string](https://neon.tech/docs/connect/connect-from-any-app) to it.
|
|
21
|
-
|
|
22
|
-
```sh
|
|
23
|
-
DATABASE_URL=postgresql://username:password@ep-adj-noun-guid.us-east-1.aws.neon.tech/neondb?sslmode=require
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
Paste the following code into your project's `index.ts` file.
|
|
29
|
-
|
|
30
|
-
```ts
|
|
31
|
-
import { neon } from "@neondatabase/serverless";
|
|
32
|
-
|
|
33
|
-
// Bun automatically loads the DATABASE_URL from .env.local
|
|
34
|
-
// Refer to: https://bun.com/docs/runtime/env for more information
|
|
35
|
-
const sql = neon(process.env.DATABASE_URL);
|
|
36
|
-
|
|
37
|
-
const rows = await sql`SELECT version()`;
|
|
38
|
-
|
|
39
|
-
console.log(rows[0].version);
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
Start the program using `bun ./index.ts`. The Postgres version should be printed to the console.
|
|
45
|
-
|
|
46
|
-
```sh
|
|
47
|
-
$ bun ./index.ts
|
|
48
|
-
PostgreSQL 16.2 on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
---
|
|
52
|
-
|
|
53
|
-
This example used the Neon serverless driver's SQL-over-HTTP functionality. Neon's serverless driver also exposes `Client` and `Pool` constructors to enable sessions, interactive transactions, and node-postgres compatibility.
|
|
54
|
-
|
|
55
|
-
Refer to [Neon's documentation](https://neon.tech/docs/serverless/serverless-driver) for a complete overview of the serverless driver.
|