goldlapel-prisma 0.0.1-rc1

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.
Files changed (3) hide show
  1. package/README.md +68 -0
  2. package/index.js +21 -0
  3. package/package.json +32 -0
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # goldlapel-prisma
2
+
3
+ Gold Lapel plugin for [Prisma](https://www.prisma.io/) — automatic Postgres query optimization with one line of code.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install goldlapel goldlapel-prisma
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ### Option A: `withGoldLapel()` (Prisma v5/v6)
14
+
15
+ Returns a wired `PrismaClient` with the connection routed through Gold Lapel:
16
+
17
+ ```javascript
18
+ import { withGoldLapel } from 'goldlapel-prisma'
19
+
20
+ const prisma = await withGoldLapel()
21
+
22
+ const users = await prisma.user.findMany()
23
+ ```
24
+
25
+ ### Option B: `init()` (all Prisma versions)
26
+
27
+ Rewrites `DATABASE_URL` to point at the proxy. You construct `PrismaClient` yourself — works with Prisma v5, v6, and v7+:
28
+
29
+ ```javascript
30
+ import { init } from 'goldlapel-prisma'
31
+
32
+ await init()
33
+
34
+ // Now create PrismaClient as usual — it reads the rewritten DATABASE_URL
35
+ import { PrismaClient } from '@prisma/client'
36
+ const prisma = new PrismaClient()
37
+ ```
38
+
39
+ ## Prisma v7 note
40
+
41
+ Prisma v7 removed the `datasources` constructor override. Use `init()` instead of `withGoldLapel()` — it rewrites `process.env.DATABASE_URL` before you create the client.
42
+
43
+ ## Options
44
+
45
+ Both `withGoldLapel()` and `init()` accept an options object:
46
+
47
+ | Option | Description |
48
+ |--------|-------------|
49
+ | `url` | Upstream Postgres URL. Defaults to `process.env.DATABASE_URL`. |
50
+ | `port` | Port for the Gold Lapel proxy. Defaults to `7932`. |
51
+ | `config` | Configuration object with camelCase keys (see below). |
52
+ | `extraArgs` | Array of extra CLI args passed to the Gold Lapel binary. |
53
+
54
+ ```javascript
55
+ const prisma = await withGoldLapel({
56
+ url: 'postgresql://user:pass@host:5432/mydb',
57
+ port: 9000,
58
+ config: { mode: 'butler', poolSize: 30, disableN1: true },
59
+ })
60
+ ```
61
+
62
+ ## Re-exports
63
+
64
+ For convenience, `goldlapel-prisma` re-exports everything from `goldlapel`:
65
+
66
+ ```javascript
67
+ import { start, stop, proxyUrl, GoldLapel } from 'goldlapel-prisma'
68
+ ```
package/index.js ADDED
@@ -0,0 +1,21 @@
1
+ import { start, stop, proxyUrl, GoldLapel } from 'goldlapel'
2
+
3
+ export async function withGoldLapel(options = {}) {
4
+ const url = options.url || process.env.DATABASE_URL
5
+ if (!url) throw new Error('Gold Lapel: DATABASE_URL not set. Pass { url } or set DATABASE_URL.')
6
+ const startFn = options._start || start
7
+ const proxy = await startFn(url, { config: options.config, port: options.port, extraArgs: options.extraArgs })
8
+ const PC = options._PrismaClient || (await import('@prisma/client')).PrismaClient
9
+ return new PC({ datasources: { db: { url: proxy } } })
10
+ }
11
+
12
+ export async function init(options = {}) {
13
+ const url = options.url || process.env.DATABASE_URL
14
+ if (!url) throw new Error('Gold Lapel: DATABASE_URL not set. Pass { url } or set DATABASE_URL.')
15
+ const startFn = options._start || start
16
+ const proxy = await startFn(url, { config: options.config, port: options.port, extraArgs: options.extraArgs })
17
+ process.env.DATABASE_URL = proxy
18
+ return proxy
19
+ }
20
+
21
+ export { start, stop, proxyUrl, GoldLapel }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "goldlapel-prisma",
3
+ "version": "0.0.1-rc1",
4
+ "description": "Gold Lapel plugin for Prisma — automatic Postgres query optimization",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "exports": "./index.js",
8
+ "files": [
9
+ "index.js"
10
+ ],
11
+ "peerDependencies": {
12
+ "@prisma/client": ">=5.0.0",
13
+ "goldlapel": ">=0.1.0"
14
+ },
15
+ "scripts": {
16
+ "test": "node --test test/test.js"
17
+ },
18
+ "keywords": [
19
+ "postgres",
20
+ "prisma",
21
+ "optimization",
22
+ "goldlapel"
23
+ ],
24
+ "license": "SEE LICENSE IN LICENSE",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/goldlapel/goldlapel-prisma"
28
+ },
29
+ "devDependencies": {
30
+ "goldlapel": "file:../goldlapel-js"
31
+ }
32
+ }