Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions generator-prisma-client/aws-lambda-sst-esbuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ This project showcases how to use the Prisma ORM with AWS Lambda and Prisma Post

To successfully run the project, you will need the following:

- Two **Prisma Postgres** connection strings:
- Your **Prisma Postgres + Accelerate connection string** (containing your **Prisma API key**) which you can get by enabling Postgres in a project in your [Prisma Data Platform](https://pris.ly/pdp) account. You will use this connection string to run Prisma migrations.
- Your **Prisma Postgres direct TCP connection string** which you will use with Prisma Client.
Learn more in the [docs](https://www.prisma.io/docs/postgres/database/direct-connections).
- A **Prisma Postgres** connection string which you can get by enabling Postgres in a project in your [Prisma Data Platform](https://pris.ly/pdp) account. This connection string will be used for both Prisma migrations and Prisma Client queries.

## Tech Stack

Expand All @@ -24,13 +21,11 @@ To successfully run the project, you will need the following:
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
previewFeatures = ["driverAdapters", "queryCompiler"]
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}
```

Expand All @@ -54,21 +49,16 @@ Create a `.env` in the root of the project directory:
touch .env
```

Now, open the `.env` file and set the `DATABASE_URL` environment variables with the values of your connection string and your Prisma Postgres connection string:
Now, open the `.env` file and set the `DATABASE_URL` environment variable with your Prisma Postgres connection string:

```bash
# .env

# Prisma Postgres connection string (used for migrations)
# Prisma Postgres connection string
DATABASE_URL="__YOUR_PRISMA_POSTGRES_CONNECTION_STRING__"

# Postgres connection string (used for queries by Prisma Client)
DIRECT_URL="__YOUR_PRISMA_POSTGRES_DIRECT_CONNECTION_STRING__"
```

Note that `__YOUR_PRISMA_POSTGRES_CONNECTION_STRING__` is a placeholder value that you need to replace with the values of your Prisma Postgres + Accelerate connection string. Notice that the Accelerate connection string has the following structure: `prisma+postgres://accelerate.prisma-data.net/?api_key=<api_key_value>`.

Note that `__YOUR_PRISMA_POSTGRES_DIRECT_CONNECTION_STRING__` is a placeholder value that you need to replace with the values of your Prisma Postgres direct TCP connection string. The direct connection string has the following structure: `postgres://<username>:<password>@<host>:<port>/<database>`.
Note that `__YOUR_PRISMA_POSTGRES_CONNECTION_STRING__` is a placeholder value that you need to replace with your Prisma Postgres connection string. You can get this by enabling Postgres in a project in your [Prisma Data Platform](https://pris.ly/pdp) account.

### 3. Run a migration to create the database structure and seed the database

Expand Down Expand Up @@ -96,13 +86,13 @@ pnpm prisma generate

- Ensure you set up your AWS Credentials and have the AWS CLI installed and logged in (see [sst docs](https://sst.dev/docs/aws-accounts))
- Set up secrets in your SST project. You can do this by:
- Manually adding the `DIRECT_URL` connection string that you previously set in your `.env` file, via:
- Manually adding the `DATABASE_URL` connection string that you previously set in your `.env` file, via:
```
pnpm sst secrets add DIRECT_URL __YOUR_PRISMA_POSTGRES_DIRECT_CONNECTION_STRING__
pnpm sst secret set DATABASE_URL __YOUR_PRISMA_POSTGRES_CONNECTION_STRING__
```
- Or, by loading the `.env` file first and piping it to the `sst secrets add` command:
- Or, by loading the `.env` file first and piping it to the `sst secret set` command:
```
pnpm dotenv -- bash -c 'pnpm sst secret set DIRECT_URL "${DIRECT_URL}"'
pnpm dotenv -- bash -c 'pnpm sst secret set DATABASE_URL "${DATABASE_URL}"'
```
- Run the following command to deploy the project to AWS Lambda using sst:

Expand Down
10 changes: 5 additions & 5 deletions generator-prisma-client/aws-lambda-sst-esbuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
"dotenv-cli": "10.0.0",
"esbuild": "0.25.12",
"npm-run-all2": "6.2.6",
"prisma": "6.15.0-integration-fix-prisma-client-dirname-aws-lambda.3",
"prisma": "6.19.0",
"tsx": "4.20.6"
},
"dependencies": {
"@prisma/adapter-pg": "6.15.0-integration-fix-prisma-client-dirname-aws-lambda.3",
"@prisma/client": "6.15.0-integration-fix-prisma-client-dirname-aws-lambda.3",
"@prisma/adapter-pg": "6.19.0",
"@prisma/client": "6.19.0",
"sst": "3.17.14"
},
"packageManager": "pnpm@8.15.9+sha512.499434c9d8fdd1a2794ebf4552b3b25c0a633abcee5bb15e7b5de90f32f47b513aca98cd5cfd001c31f0db454bc3804edccd578501e4ca293a6816166bbd9f81"
}
"packageManager": "pnpm@8.15.9+"
}
84 changes: 42 additions & 42 deletions generator-prisma-client/aws-lambda-sst-esbuild/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { defineConfig } from 'prisma/config';
import { defineConfig, env } from 'prisma/config';
import 'dotenv/config';

export default defineConfig({
schema: './prisma/schema.prisma',
migrations: {
path: "./prisma/migrations",
seed: 'tsx ./prisma/seed.ts',
},
datasource: {
url: env("DATABASE_URL"),
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@

// See: https://www.prisma.io/docs/orm/prisma-schema/overview/generators#field-reference-1
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
previewFeatures = ["driverAdapters", "queryCompiler"]
provider = "prisma-client"
output = "../src/generated/prisma"
engineType = "client"
moduleFormat = "esm"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
provider = "postgresql"
url = env("DATABASE_URL")
}

enum QuoteKind {
Expand All @@ -21,8 +20,8 @@ enum QuoteKind {
}

model Quotes {
id Int @id @default(autoincrement())
id Int @id @default(autoincrement())
quote String
kind QuoteKind @default(Opinion)
createdAt DateTime @default(now())
createdAt DateTime @default(now())
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getDb } from '../src/db'
import { QuoteKind } from '../src/prisma-enums'

const prisma = getDb({ connectionString: process.env.DIRECT_URL! })
const prisma = getDb({ connectionString: process.env.DATABASE_URL! })

const main = async () => {
console.log('Seeding database...')
Expand Down
4 changes: 2 additions & 2 deletions generator-prisma-client/aws-lambda-sst-esbuild/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { APIGatewayProxyEventV2 } from 'aws-lambda';
import { Resource } from 'sst';
import { getDb } from './db';

const prisma = getDb({ connectionString: Resource.DIRECT_URL.value })
const prisma = getDb({ connectionString: Resource.DATABASE_URL.value })

export const handler = async (evt: APIGatewayProxyEventV2) => {
if (evt.requestContext.http.method !== 'GET') {
Expand All @@ -17,7 +17,7 @@ export const handler = async (evt: APIGatewayProxyEventV2) => {
}),
};
}

try {
const quotes = await prisma.quotes.findMany({ take: 2 })
return {
Expand Down
4 changes: 2 additions & 2 deletions generator-prisma-client/aws-lambda-sst-esbuild/sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export default $config({
home: "aws",
};
},

// Your app's resources.
// Note: The Global `sst` library is only available in the run function of your sst.config.ts.
async run() {
const secrets = {
directUrl: new sst.Secret("DIRECT_URL", '<placeholder_value>'),
databaseUrl: new sst.Secret("DATABASE_URL", '<placeholder_value>'),
}
const allSecrets = Object.values(secrets)

Expand Down
9 changes: 5 additions & 4 deletions generator-prisma-client/basic-typedsql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
"author": "",
"license": "ISC",
"dependencies": {
"@prisma/client": "6.14.0"
"@prisma/adapter-better-sqlite3": "^6.19.0",
"@prisma/client": "6.19.0"
},
"devDependencies": {
"@types/node": "22.18.12",
"prisma": "6.14.0",
"prisma": "6.19.0",
"tsx": "4.20.6"
},
"packageManager": "pnpm@8.15.9+sha512.499434c9d8fdd1a2794ebf4552b3b25c0a633abcee5bb15e7b5de90f32f47b513aca98cd5cfd001c31f0db454bc3804edccd578501e4ca293a6816166bbd9f81"
}
"packageManager": "pnpm@10.21.0"
}
Loading