@sqldoc/db-neon 0.0.10

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 (2) hide show
  1. package/package.json +25 -0
  2. package/src/index.ts +49 -0
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "type": "module",
3
+ "name": "@sqldoc/db-neon",
4
+ "version": "0.0.10",
5
+ "description": "Neon serverless PostgreSQL adapter for sqldoc (drift detection against live Neon databases)",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./src/index.ts",
9
+ "import": "./src/index.ts",
10
+ "default": "./src/index.ts"
11
+ }
12
+ },
13
+ "main": "./src/index.ts",
14
+ "types": "./src/index.ts",
15
+ "files": [
16
+ "src",
17
+ "package.json"
18
+ ],
19
+ "dependencies": {
20
+ "@neondatabase/serverless": "^0.10.0"
21
+ },
22
+ "devDependencies": {
23
+ "@sqldoc/db": "0.0.10"
24
+ }
25
+ }
package/src/index.ts ADDED
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Neon serverless PostgreSQL adapter for sqldoc.
3
+ *
4
+ * Connects to an existing Neon database using @neondatabase/serverless.
5
+ * Intended for read-only use cases like drift detection against a live
6
+ * Neon database (schema diff against production).
7
+ *
8
+ * devUrl format: neon://ep-xxx.us-east-2.aws.neon.tech/dbname
9
+ */
10
+ import { neon } from '@neondatabase/serverless'
11
+ import type { AdapterPluginContext, DatabaseAdapter, DatabaseAdapterPlugin, ExecResult, QueryResult } from '@sqldoc/db'
12
+ import { normalizeValue } from '@sqldoc/db'
13
+
14
+ const plugin: DatabaseAdapterPlugin = {
15
+ apiVersion: 1,
16
+ name: 'neon',
17
+ schemes: ['neon'],
18
+ dialects: ['postgres'],
19
+ runtime: 'any',
20
+
21
+ async createAdapter(devUrl: string, _context: AdapterPluginContext): Promise<DatabaseAdapter> {
22
+ // Transform neon:// → postgres:// for the serverless driver
23
+ const connectionString = devUrl.replace(/^neon:\/\//, 'postgres://')
24
+ const sql = neon(connectionString, { fullResults: true })
25
+
26
+ return {
27
+ async query(queryText: string, args?: unknown[]): Promise<QueryResult> {
28
+ const result = args && args.length > 0 ? await sql(queryText, args) : await sql(queryText)
29
+ if (result.rows.length === 0) {
30
+ return { columns: result.fields.map((f) => f.name), rows: [] }
31
+ }
32
+ const columns = result.fields.map((f) => f.name)
33
+ return {
34
+ columns,
35
+ rows: result.rows.map((row: Record<string, unknown>) => columns.map((c) => normalizeValue(row[c]))),
36
+ }
37
+ },
38
+ async exec(queryText: string, args?: unknown[]): Promise<ExecResult> {
39
+ const result = args && args.length > 0 ? await sql(queryText, args) : await sql(queryText)
40
+ return { rowsAffected: result.rowCount ?? 0 }
41
+ },
42
+ async close(): Promise<void> {
43
+ // Neon serverless is stateless — no connection to close
44
+ },
45
+ }
46
+ },
47
+ }
48
+
49
+ export default plugin