From 29d2fba7d46811d12c7bb2fc46959f4a88e9a4b1 Mon Sep 17 00:00:00 2001 From: Jo Franchetti Date: Thu, 15 Jan 2026 13:45:50 +0000 Subject: [PATCH] remove old and out of date db tutorials, link to new deploy db instead --- deploy/classic/_data.ts | 13 -- deploy/classic/dynamodb.md | 108 --------------- deploy/classic/firebase.md | 177 ------------------------- deploy/classic/neon-postgres.md | 119 ----------------- deploy/classic/postgres.md | 132 ------------------- deploy/classic/prisma-postgres.md | 210 ------------------------------ oldurls.json | 7 +- 7 files changed, 6 insertions(+), 760 deletions(-) delete mode 100644 deploy/classic/dynamodb.md delete mode 100644 deploy/classic/firebase.md delete mode 100644 deploy/classic/neon-postgres.md delete mode 100644 deploy/classic/postgres.md delete mode 100644 deploy/classic/prisma-postgres.md diff --git a/deploy/classic/_data.ts b/deploy/classic/_data.ts index 3b7262cc3..cdcf03c4e 100644 --- a/deploy/classic/_data.ts +++ b/deploy/classic/_data.ts @@ -69,19 +69,6 @@ export const sidebar = [ title: "Deno KV", href: "/deploy/classic/kv_on_deploy/", }, - { - title: "Third-Party Databases", - items: [ - { title: "DynamoDB", href: "/deploy/classic/dynamodb/" }, - { title: "Firebase", href: "/deploy/classic/firebase/" }, - { title: "Postgres", href: "/deploy/classic/postgres/" }, - { title: "Neon Postgres", href: "/deploy/classic/neon-postgres/" }, - { - title: "Prisma Postgres", - href: "/deploy/classic/prisma-postgres/", - }, - ], - }, ], }, { diff --git a/deploy/classic/dynamodb.md b/deploy/classic/dynamodb.md deleted file mode 100644 index f5f78bed0..000000000 --- a/deploy/classic/dynamodb.md +++ /dev/null @@ -1,108 +0,0 @@ ---- -title: "Connect to DynamoDB" ---- - -:::info Legacy Documentation - -You are viewing legacy documentation for Deno Deploy Classic. We recommend -migrating to the new -Deno Deploy platform. - -::: - -Amazon DynamoDB is a fully managed NoSQL database. To persist data to DynamoDB, -follow the steps below: - -The tutorial assumes that you have an AWS and Deno Deploy Classic account. - -## Gather credentials from DynamoDB - -The first step in the process is to generate AWS credentials to programmatically -access DynamoDB. - -Generate Credentials: - -1. Go to https://console.aws.amazon.com/iam/ and go to the "Users" section. -2. Click on the **Add user** button, fill the **User name** field (maybe use - `denamo`), and select **Programmatic access** type. -3. Click on **Next: Permissions**, then on **Attach existing policies - directly**, search for `AmazonDynamoDBFullAccess` and select it. -4. Click on **Next: Tags**, then on **Next: Review** and finally **Create - user**. -5. Click on **Download .csv** button to download the credentials. - -## Create a project in Deno Deploy - -Next, let's create a project in Deno Deploy Classic and set it up with the -requisite environment variables: - -1. Go to [https://dash.deno.com/new](https://dash.deno.com/new) (Sign in with - GitHub if you didn't already) and click on **+ Empty Project** under **Deploy - from the command line**. -2. Now click on the **Settings** button available on the project page. -3. Navigate to **Environment Variables** Section and add the following secrets. - -- `AWS_ACCESS_KEY_ID` - Use the value that's available under **Access key ID** - column in the downloaded CSV. -- `AWS_SECRET_ACCESS_KEY` - Use the value that's available under **Secret access - key** column in the downloaded CSV. - -## Write code that connects to DynamoDB - -AWS has an -[official SDK](https://www.npmjs.com/package/@aws-sdk/client-dynamodb) that -works with browsers. As most Deno Deploy's APIs are similar to browsers', the -same SDK works with Deno Deploy. To use the SDK in Deno, import from a cdn like -below and create a client: - -```js -import { - DynamoDBClient, - GetItemCommand, - PutItemCommand, -} from "https://esm.sh/@aws-sdk/client-dynamodb?dts"; - -// Create a client instance by providing your region information. -// The credentials are automatically obtained from environment variables which -// we set during our project creation step on Deno Deploy, so we don't have to -// pass them manually here. -const client = new ApiFactory().makeNew(DynamoDB); - -serve({ - "/songs": handleRequest, -}); - -async function handleRequest(request) { - // async/await. - try { - const data = await client.send(command); - // process data. - } catch (error) { - // error handling. - } finally { - // finally. - } -} -``` - -## Deploy application to Deno Deploy Classic - -Once you have finished writing your application, you can deploy it on Deno -Deploy Classic. - -To do this, go back to your project page at -`https://dash.deno.com/projects/`. - -You should see a couple of options to deploy: - -- [Github integration](ci_github) -- [`deployctl`](./deployctl.md) - ```sh - deployctl deploy --project= - ``` - -Unless you want to add a build step, we recommend that you select the Github -integration. - -For more details on the different ways to deploy on Deno Deploy Classic and the -different configuration options, read [here](how-to-deploy). diff --git a/deploy/classic/firebase.md b/deploy/classic/firebase.md deleted file mode 100644 index 9b7630bd2..000000000 --- a/deploy/classic/firebase.md +++ /dev/null @@ -1,177 +0,0 @@ ---- -title: "Connect to Firebase" ---- - -:::info Legacy Documentation - -You are viewing legacy documentation for Deno Deploy Classic. We recommend -migrating to the new -Deno Deploy platform. - -::: - -Firebase is a platform developed by Google for creating mobile and web -applications. Its features include authentication primitives for log in and a -NoSQL datastore, Firestore, that you can persist data to. - -This tutorial covers how to connect to Firebase from an application deployed on -Deno Deploy. - -## Get credentials from Firebase - -> This tutorial assumes that you've already created a project in Firebase and -> added a web application to your project. - -1. Navigate to your project in Firebase and click on **Project Settings** -2. Scroll down until you see a card with your app name, and a code sample that - includes a `firebaseConfig`object. It should look something like the below. - Keep this handy. We will use it later: - - ```js - var firebaseConfig = { - apiKey: "APIKEY", - authDomain: "example-12345.firebaseapp.com", - projectId: "example-12345", - storageBucket: "example-12345.appspot.com", - messagingSenderId: "1234567890", - appId: "APPID", - }; - ``` - -## Create a Project in Deno Deploy - -1. Go to [https://dash.deno.com/new](https://dash.deno.com/new) (Sign in with - GitHub if you didn't already) and click on **+ Empty Project** under **Deploy - from the command line**. -2. Now click on the **Settings** button available on the project page. -3. Navigate to the **Environment Variables** section and add the following: - -
-
FIREBASE_USERNAME
-
The Firebase user (email address) that was added above.
-
FIREBASE_PASSWORD
-
The Firebase user password that was added above.
-
FIREBASE_CONFIG
-
The configuration of the Firebase application as a JSON string.
-
- - The configuration needs to be a valid JSON string to be readable by the - application. If the code snippet given when setting up looked like this: - - ```js - var firebaseConfig = { - apiKey: "APIKEY", - authDomain: "example-12345.firebaseapp.com", - projectId: "example-12345", - storageBucket: "example-12345.appspot.com", - messagingSenderId: "1234567890", - appId: "APPID", - }; - ``` - - You would need to set the value of the string to this (noting that spacing - and new lines are not required): - - ```json - { - "apiKey": "APIKEY", - "authDomain": "example-12345.firebaseapp.com", - "projectId": "example-12345", - "storageBucket": "example-12345.appspot.com", - "messagingSenderId": "1234567890", - "appId": "APPID" - } - ``` - -## Write code that connects to Firebase - -The first thing we will do is import the `XMLHttpRequest` polyfill that Firebase -needs to work under Deploy as well as a polyfill for `localStorage` to allow the -Firebase auth to persist logged in users: - -```js -import "https://deno.land/x/xhr@0.1.1/mod.ts"; -import { installGlobals } from "https://deno.land/x/virtualstorage@0.1.0/mod.ts"; -installGlobals(); -``` - -> ℹ️ we are using the current version of packages at the time of the writing of -> this tutorial. They may not be up-to-date and you may want to double check -> current versions. - -Because Deploy has a lot of the web standard APIs, it is best to use the web -libraries for Firebase under deploy. Currently v9 is in still in beta for -Firebase, so we will use v8: - -```js -import firebase from "https://esm.sh/firebase@9.17.0/app"; -import "https://esm.sh/firebase@9.17.0/auth"; -import "https://esm.sh/firebase@9.17.0/firestore"; -``` - -Now we need to setup our Firebase application. We will be getting the -configuration from the environment variables we set up previously and get -references to the parts of Firebase we are going to use: - -```js -const firebaseConfig = JSON.parse(Deno.env.get("FIREBASE_CONFIG")); -const firebaseApp = firebase.initializeApp(firebaseConfig, "example"); -const auth = firebase.auth(firebaseApp); -const db = firebase.firestore(firebaseApp); -``` - -Ok, we are almost done. We just need to create our middleware application and -add the `localStorage` middleware we imported: - -```js -const app = new Application(); -app.use(virtualStorage()); -``` - -And then we need to add middleware to authenticate the user. In this tutorial we -are simply grabbing the username and password from the environment variables we -will be setting up, but this could easily be adapted to redirect a user to a -sign-in page if they are not logged in: - -```js -app.use(async (ctx, next) => { - const signedInUid = ctx.cookies.get("LOGGED_IN_UID"); - const signedInUser = signedInUid != null ? users.get(signedInUid) : undefined; - if (!signedInUid || !signedInUser || !auth.currentUser) { - const creds = await auth.signInWithEmailAndPassword( - Deno.env.get("FIREBASE_USERNAME"), - Deno.env.get("FIREBASE_PASSWORD"), - ); - const { user } = creds; - if (user) { - users.set(user.uid, user); - ctx.cookies.set("LOGGED_IN_UID", user.uid); - } else if (signedInUser && signedInUid.uid !== auth.currentUser?.uid) { - await auth.updateCurrentUser(signedInUser); - } - } - return next(); -}); -``` - -## Deploy the application to Deno Deploy - -Once you have finished writing your application, you can deploy it on Deno -Deploy. - -To do this, go back to your project page at -`https://dash.deno.com/projects/`. - -You should see a couple of options to deploy: - -- [Github integration](ci_github) -- [`deployctl`](./deployctl.md) - ```sh - deployctl deploy --project= - ``` - -Unless you want to add a build step, we recommend that you select the Github -integration. - -For more details on the different ways to deploy on Deno Deploy Classic and the -different configuration options, read [here](how-to-deploy). diff --git a/deploy/classic/neon-postgres.md b/deploy/classic/neon-postgres.md deleted file mode 100644 index 54a3a57dc..000000000 --- a/deploy/classic/neon-postgres.md +++ /dev/null @@ -1,119 +0,0 @@ ---- -title: "Connect to Neon Postgres" ---- - -:::info Legacy Documentation - -You are viewing legacy documentation for Deno Deploy Classic. We recommend -migrating to the new -Deno Deploy platform. - -::: - -This tutorial covers how to connect to a Neon Postgres database from an -application deployed on Deno Deploy. - -## Setup Postgres - -To get started, we need to create a new Postgres instance for us to connect to. -For this tutorial, we will be using [Neon Postgres](https://neon.tech/) as they -provide free, managed Postgres instances. If you like to host your database -somewhere else, you can do that too. - -1. Visit https://neon.tech/ and click **Sign up** to sign up with an email, - Github, Google, or partner account. After signing up, you are directed to the - Neon Console to create your first project. -2. Enter a name for your project, select a Postgres version, provide a database - name, and select a region. Generally, you'll want to select the region - closest to your application. When you're finished, click **Create project**. -3. You are presented with the connection string for your new project, which you - can use to connect to your database. Save the connection string, which looks - something like this: - - ```sh - postgres://alex:AbC123dEf@ep-cool-darkness-123456.us-east-2.aws.neon.tech/dbname?sslmode=require - ``` - - You will need the connection string in the next step. - -## Create a project in Deno Deploy - -Next, let's create a project in Deno Deploy Classic and set it up with the -requisite environment variables: - -1. Go to [https://dash.deno.com/new](https://dash.deno.com/new) (Sign in with - GitHub if you didn't already) and click on **Create an empty project** under - **Deploy your own code**. -2. Now click on the **Settings** button available on the project page. -3. Navigate to **Environment Variables** Section and add the following secret. - -- `DATABASE_URL` - The value should be set to the connection string you saved in - the last step. - -![postgres_env_variable](../docs-images/neon_postgres_env_variable.png) - -## Write code that connects to Postgres - -To read/write to Postgres using the -[Neon serverless driver](https://deno.com/blog/neon-on-jsr), first install it -using the `deno add` command: - -```sh -deno add jsr:@neon/serverless -``` - -This will create or update your `deno.json` file with the dependency: - -```json -{ - "imports": { - "@neon/serverless": "jsr:@neon/serverless@^0.10.1" - } -} -``` - -Now you can use the driver in your code: - -```ts -import { neon } from "@neon/serverless"; - -// Get the connection string from the environment variable "DATABASE_URL" -const databaseUrl = Deno.env.get("DATABASE_URL")!; - -// Create a SQL query executor -const sql = neon(databaseUrl); - -try { - // Create the table - await sql` - CREATE TABLE IF NOT EXISTS todos ( - id SERIAL PRIMARY KEY, - title TEXT NOT NULL - ) - `; -} catch (error) { - console.error(error); -} -``` - -## Deploy application to Deno Deploy Classic - -Once you have finished writing your application, you can deploy it on Deno -Deploy Classic. - -To do this, go back to your project page at -`https://dash.deno.com/projects/`. - -You should see a couple of options to deploy: - -- [Github integration](ci_github) -- [`deployctl`](./deployctl.md) - ```sh - deployctl deploy --project= - ``` - -Unless you want to add a build step, we recommend that you select the GitHub -integration. - -For more details on the different ways to deploy on Deno Deploy Classic and the -different configuration options, read [here](how-to-deploy). diff --git a/deploy/classic/postgres.md b/deploy/classic/postgres.md deleted file mode 100644 index f672f0c77..000000000 --- a/deploy/classic/postgres.md +++ /dev/null @@ -1,132 +0,0 @@ ---- -title: "Connect to Postgres" ---- - -:::info Legacy Documentation - -You are viewing legacy documentation for Deno Deploy Classic. We recommend -migrating to the new -Deno Deploy platform. - -::: - -This tutorial covers how to connect to a Postgres database from an application -deployed on Deno Deploy. - -## Setup Postgres - -> This tutorial will focus entirely on connecting to Postgres unencrypted. If -> you would like to use encryption with a custom CA certificate, use the -> documentation [here](https://deno-postgres.com/#/?id=ssltls-connection). - -To get started, we need to create a new Postgres instance for us to connect to. -For this tutorial, we will be using [Supabase](https://supabase.com) as they -provide free, managed Postgres instances. If you like to host your database -somewhere else, you can do that too. - -1. Visit https://app.supabase.io/ and click **New project**. -2. Select a name, password, and region for your database. Make sure to save the - password, as you will need it later. -3. Click **Create new project**. Creating the project can take a while, so be - patient. - -## Gather credentials from Postgres - -Once you've set up your Postgres database, gather your connection information -from your Postgres instance. - -### Supabase - -For the Supabase instance above, to get your connection information: - -1. Navigate to the **Database** tab on the left. -2. Go to the **Project Settings** >> **Database** and copy the connection string - from the **Connection String** >> **URI** field. This is the connection - string you will use to connect to your database. Insert the password you - saved earlier into this string, and then save the string somewhere - you will - need it later. - -### psql - -If you are using psql, you should generally be able to find your connection -information by running: - -```psql -test=# \conninfo -``` - -Your Postgres connection string will take the form: - -```sh -postgres://user:password@127.0.0.1:5432/deploy?sslmode=disable -``` - -## Create a project in Deno Deploy - -Next, let's create a project in Deno Deploy Classic and set it up with the -requisite environment variables: - -1. Go to [https://dash.deno.com/new](https://dash.deno.com/new) (Sign in with - GitHub if you didn't already) and click on **+ Empty Project** under **Deploy - from the command line**. -2. Now click on the **Settings** button available on the project page. -3. Navigate to **Environment Variables** Section and add the following secrets. - -- `DATABASE_URL` - The value should be your connection string that you retrieved - in the last step. - -![postgres_env_variable](../docs-images/postgres_env_variable.png) - -## Write code that connects to Postgres - -To read/write to Postgres, import a suitable Postgres module such as -[this one from JSR](https://jsr.io/@bartlomieju/postgres), read the connection -string from the environment variables, and create a connection pool. - -```ts -import { Pool } from "jsr:@bartlomieju/postgres"; - -// Get the connection string from the environment variable "DATABASE_URL" -const databaseUrl = Deno.env.get("DATABASE_URL")!; - -// Create a database pool with three connections that are lazily established -const pool = new Pool(databaseUrl, 3, true); - -// Connect to the database -const connection = await pool.connect(); - -try { - // Create the table - await connection.queryObject` - CREATE TABLE IF NOT EXISTS todos ( - id SERIAL PRIMARY KEY, - title TEXT NOT NULL - ) - `; -} finally { - // Release the connection back into the pool - connection.release(); -} -``` - -## Deploy application to Deno Deploy Classic - -Once you have finished writing your application, you can deploy it on Deno -Deploy Classic. - -To do this, go back to your project page at -`https://dash.deno.com/projects/`. - -You should see a couple of options to deploy: - -- [Github integration](ci_github) -- [`deployctl`](./deployctl.md) - ```sh - deployctl deploy --project= - ``` - -Unless you want to add a build step, we recommend that you select the Github -integration. - -For more details on the different ways to deploy on Deno Deploy Classic and the -different configuration options, read [here](how-to-deploy). diff --git a/deploy/classic/prisma-postgres.md b/deploy/classic/prisma-postgres.md deleted file mode 100644 index 56dc3bb9a..000000000 --- a/deploy/classic/prisma-postgres.md +++ /dev/null @@ -1,210 +0,0 @@ ---- -title: "Connect to Prisma Postgres" ---- - -:::info Legacy Documentation - -You are viewing legacy documentation for Deno Deploy Classic. We recommend -migrating to the new -Deno Deploy platform. - -::: - -This tutorial covers how to connect to a Prisma Postgres database from an -application deployed on Deno Deploy. - -## Setup Postgres - -There are several ways to set up a Prisma Postgre database for your Prisma -project. This guide covers the most common approaches. - -### Method 1: Using Prisma CLI - -Run the following command to initialize a new Prisma project with a database: - -```bash -npx prisma init --db -``` - -This will prompt you to select your preferred region and database name. Once -completed, you'll find the `DATABASE_URL` connection string in your `.env` file. - -### Method 2: Using `npx create-db` - -Alternatively, you can use the dedicated database creation tool: - -```bash -npx create-db@latest -``` - -This command will provide you with two connection strings tied to the same -database: - -**Prisma ORM optimized connection string:** - -```txt -prisma+postgres://accelerate.prisma-data.net/?api_key= -``` - -**Standard Prisma Postgres connection string:** - -```txt -postgresql://:@db.prisma.io:5432/postgres -``` - -In order to keep the database created with `npx create-db`, you must follow -through with the claim process. That can be done via the claim link provided in -the terminal. - -The Prisma ORM optimized connection string (`prisma+postgres://`) only works -with the Prisma ORM, while the standard Prisma Postgre connection string can be -used with other database tools and libraries. - -## Create a project in Deno Deploy - -Next, let's create a project in Deno Deploy Classic and set it up with the -requisite environment variables: - -1. Go to [https://dash.deno.com/new](https://dash.deno.com/new) (Sign in with - GitHub if you didn't already) and click on **Create an empty project** under - **Deploy your own code**. -2. Now click on the **Settings** button available on the project page. -3. Navigate to **Environment Variables** Section and add the following secret. - -- `DATABASE_URL` - The value should be set to the connection string you saved in - the last step. - -![postgres_env_variable](../docs-images/prisma_postgres_env_variable.png) - -## Write code that connects to Postgres - -Now that you have your database set up, let's create a simple application that -connects to the Prisma Postgres database using Prisma ORM. - -### 1. Install dependencies - -First, install the required dependencies: - -```bash -deno install npm:@prisma/client -deno install npm:@prisma/extension-accelerate -deno install npm:dotenv-cli -``` - -:::note - -The `dotenv-cli` package is needed because Prisma Client doesn't read `.env` -files by default on Deno. - -::: - -### 2. Create the database schema - -With your database connection configured, you can now apply the data model to -your database: - -```bash -deno run -A npm:prisma migrate dev --name init -``` - -This command creates a new SQL migration file and runs it against your database. - -### 3. Update your Prisma schema - -Edit your `prisma/schema.prisma` file to define a `Log` model and configure it -for Deno: - -```ts -generator client { - provider = "prisma-client" - output = "../generated/prisma" - runtime = "deno" -} - -datasource db { - provider = "postgresql" - url = env("DATABASE_URL") -} - -model Log { - id Int @id @default(autoincrement()) - level Level - message String - meta Json -} - -enum Level { - Info - Warn - Error -} -``` - -### 4. Create your application - -Create `index.ts` in your project root with the following content: - -```typescript -import { serve } from "https://deno.land/std@0.140.0/http/server.ts"; -import { withAccelerate } from "npm:@prisma/extension-accelerate"; -import { PrismaClient } from "./generated/prisma/client.ts"; - -const prisma = new PrismaClient().$extends(withAccelerate()); - -async function handler(request: Request) { - // Ignore /favicon.ico requests: - const url = new URL(request.url); - if (url.pathname === "/favicon.ico") { - return new Response(null, { status: 204 }); - } - - const log = await prisma.log.create({ - data: { - level: "Info", - message: `${request.method} ${request.url}`, - meta: { - headers: JSON.stringify(request.headers), - }, - }, - }); - const body = JSON.stringify(log, null, 2); - return new Response(body, { - headers: { "content-type": "application/json; charset=utf-8" }, - }); -} - -serve(handler); -``` - -### 4. Test your application locally - -Start your application locally to test the database connection: - -```bash -npx dotenv -- deno run -A ./index.ts -``` - -Visit `http://localhost:8000` in your browser. Each request will create a new -log entry in your database and return the log data as JSON. - -## Deploy application to Deno Deploy Classic - -Once you have finished writing your application, you can deploy it on Deno -Deploy Classic. - -To do this, go back to your project page at -`https://dash.deno.com/projects/`. - -You should see a couple of options to deploy: - -- [Github integration](ci_github) -- [`deployctl`](./deployctl.md) - ```sh - deployctl deploy --project= - ``` - -Unless you want to add a build step, we recommend that you select the GitHub -integration. - -For more details on the different ways to deploy on Deno Deploy Classic and the -different configuration options, read [here](how-to-deploy). diff --git a/oldurls.json b/oldurls.json index dea4523b9..8d1382154 100644 --- a/oldurls.json +++ b/oldurls.json @@ -148,5 +148,10 @@ "/deploy/kv/tutorials/schedule_notification/": "/examples/", "/deploy/kv/tutorials/webhook_processor/": "/examples/", "/runtime/fundamentals/standard_library/": "/runtime/reference/std/", - "/deploy/classic/faunadb/": "/examples/#connecting-to-databases" + "/deploy/classic/faunadb/": "/deploy/reference/databases/", + "/deploy/classic/dynamodb/": "/deploy/reference/databases/", + "/deploy/classic/firebase/": "/deploy/reference/databases/", + "/deploy/classic/postgres/": "/deploy/reference/databases/", + "/deploy/classic/prisma-postgres/": "/deploy/reference/databases/", + "/deploy/classic/neon-postgres/": "/deploy/reference/databases/" }