@yottagraph-app/aether-instructions 1.1.15 → 1.1.16
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/package.json +1 -1
- package/rules/server.mdc +42 -25
package/package.json
CHANGED
package/rules/server.mdc
CHANGED
|
@@ -19,7 +19,8 @@ server/
|
|
|
19
19
|
│ ├── kv/ # KV (Upstash Redis) CRUD — read, write, delete, documents, status
|
|
20
20
|
│ └── avatar/[url].ts # Avatar image proxy
|
|
21
21
|
└── utils/
|
|
22
|
-
├── redis.ts # Upstash Redis client init
|
|
22
|
+
├── redis.ts # Upstash Redis client (lazy-init from KV_REST_API_URL)
|
|
23
|
+
├── neon.ts # Neon Postgres client (lazy-init from DATABASE_URL) — present if Neon provisioned
|
|
23
24
|
└── cookies.ts # Cookie handling (@hapi/iron)
|
|
24
25
|
```
|
|
25
26
|
|
|
@@ -69,33 +70,22 @@ Returns `null` if KV is not configured (env vars missing). Always check.
|
|
|
69
70
|
|
|
70
71
|
## Neon Postgres
|
|
71
72
|
|
|
72
|
-
If
|
|
73
|
-
`
|
|
74
|
-
|
|
75
|
-
init. Check `.env` for `DATABASE_URL` — if present, Postgres is ready to use.
|
|
73
|
+
If `DATABASE_URL` is in `.env`, Postgres is ready to use. The project init
|
|
74
|
+
scaffolds `server/utils/neon.ts` and installs `@neondatabase/serverless`
|
|
75
|
+
automatically when a Neon database is detected.
|
|
76
76
|
|
|
77
|
-
###
|
|
77
|
+
### How to check
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
`
|
|
79
|
+
- `DATABASE_URL` present in `.env` → Postgres is connected
|
|
80
|
+
- `server/utils/neon.ts` exists → utility is scaffolded
|
|
81
|
+
- If either is missing, the project wasn't provisioned with Neon (add it
|
|
82
|
+
from the Broadchurch Portal, then re-run `node init-project.js`)
|
|
81
83
|
|
|
82
|
-
|
|
83
|
-
import { neon, type NeonQueryFunction } from '@neondatabase/serverless';
|
|
84
|
+
### Usage
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (_sql) return _sql;
|
|
89
|
-
const url = process.env.DATABASE_URL;
|
|
90
|
-
if (!url) return null;
|
|
91
|
-
_sql = neon(url);
|
|
92
|
-
return _sql;
|
|
93
|
-
}
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
Install the driver: `npm install @neondatabase/serverless`
|
|
97
|
-
|
|
98
|
-
### Usage in server routes
|
|
86
|
+
`server/utils/neon.ts` exports `getDb()` (same lazy-init pattern as
|
|
87
|
+
`getRedis()` in `redis.ts`): returns a query function or `null` if
|
|
88
|
+
`DATABASE_URL` is not set.
|
|
99
89
|
|
|
100
90
|
```typescript
|
|
101
91
|
import { getDb } from '~/server/utils/neon';
|
|
@@ -109,10 +99,37 @@ export default defineEventHandler(async () => {
|
|
|
109
99
|
});
|
|
110
100
|
```
|
|
111
101
|
|
|
112
|
-
The driver uses tagged template literals for automatic SQL injection
|
|
102
|
+
The Neon driver uses tagged template literals for automatic SQL injection
|
|
113
103
|
protection — `await sql\`SELECT * FROM notes WHERE id = ${id}\`` is safe.
|
|
114
104
|
No ORM, no query builder, no connection pool setup needed.
|
|
115
105
|
|
|
106
|
+
### If `server/utils/neon.ts` doesn't exist
|
|
107
|
+
|
|
108
|
+
Create it manually (or re-run init):
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
npm install @neondatabase/serverless
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
// server/utils/neon.ts
|
|
116
|
+
import { neon, type NeonQueryFunction } from '@neondatabase/serverless';
|
|
117
|
+
|
|
118
|
+
let _sql: NeonQueryFunction | null = null;
|
|
119
|
+
|
|
120
|
+
export function isDbConfigured(): boolean {
|
|
121
|
+
return Boolean(process.env.DATABASE_URL);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function getDb(): NeonQueryFunction | null {
|
|
125
|
+
if (_sql) return _sql;
|
|
126
|
+
const url = process.env.DATABASE_URL;
|
|
127
|
+
if (!url) return null;
|
|
128
|
+
_sql = neon(url);
|
|
129
|
+
return _sql;
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
116
133
|
## Key Differences from Client-Side Code
|
|
117
134
|
|
|
118
135
|
- Server routes run on the server (Node.js), not in the browser
|