@celerity-sdk/sql-database 0.3.1 → 0.5.0

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/README.md CHANGED
@@ -2,7 +2,19 @@
2
2
 
3
3
  SQL database abstraction for the Celerity Node SDK.
4
4
 
5
- Provides a unified interface for working with SQL databases across cloud-managed offerings.
5
+ Provides credential resolution, connection pooling, and [Knex.js](https://knexjs.org) query builder instances for cloud-managed SQL databases:
6
+
7
+ - **AWS**: Amazon RDS (PostgreSQL, MySQL)
8
+ - **GCP**: Google Cloud SQL *(planned)*
9
+ - **Azure**: Azure Database *(planned)*
10
+
11
+ ## Features
12
+
13
+ - **Dual auth modes** — password-based and IAM token-based authentication
14
+ - **Read replicas** — optional separate reader instance with automatic fallback to the writer
15
+ - **Deploy-aware pool presets** — tuned defaults for serverless functions vs. long-running containers
16
+ - **DI integration** — parameter decorators for injecting Knex instances into handler classes
17
+ - **BYO ORM** — inject `SqlDatabaseCredentials` directly for use with Prisma, Drizzle, or any other ORM
6
18
 
7
19
  ## Installation
8
20
 
@@ -10,9 +22,109 @@ Provides a unified interface for working with SQL databases across cloud-managed
10
22
  pnpm add @celerity-sdk/sql-database
11
23
  ```
12
24
 
25
+ Install Knex and a database driver as peer dependencies:
26
+
27
+ ```bash
28
+ # PostgreSQL
29
+ pnpm add knex pg
30
+
31
+ # MySQL
32
+ pnpm add knex mysql2
33
+ ```
34
+
35
+ For IAM authentication on AWS:
36
+
37
+ ```bash
38
+ pnpm add @aws-sdk/rds-signer
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ### Basic usage
44
+
45
+ ```typescript
46
+ import { Injectable } from "@celerity-sdk/core";
47
+ import { SqlDatabase } from "@celerity-sdk/sql-database";
48
+ import type { Knex } from "knex";
49
+
50
+ @Injectable()
51
+ class UserService {
52
+ constructor(@SqlDatabase() private readonly db: Knex) {}
53
+
54
+ async findById(id: string) {
55
+ return this.db("users").where("id", id).first();
56
+ }
57
+
58
+ async create(name: string, email: string) {
59
+ const [user] = await this.db("users")
60
+ .insert({ name, email })
61
+ .returning("*");
62
+ return user;
63
+ }
64
+ }
65
+ ```
66
+
67
+ ### Writer / reader split
68
+
69
+ Use `@SqlWriter()` and `@SqlReader()` when a read replica is configured:
70
+
71
+ ```typescript
72
+ import { Injectable } from "@celerity-sdk/core";
73
+ import { SqlWriter, SqlReader } from "@celerity-sdk/sql-database";
74
+ import type { Knex } from "knex";
75
+
76
+ @Injectable()
77
+ class UserService {
78
+ constructor(
79
+ @SqlWriter() private readonly writer: Knex,
80
+ @SqlReader() private readonly reader: Knex,
81
+ ) {}
82
+ }
83
+ ```
84
+
85
+ ### BYO ORM (credentials only)
86
+
87
+ ```typescript
88
+ import { Injectable } from "@celerity-sdk/core";
89
+ import { SqlCredentials } from "@celerity-sdk/sql-database";
90
+ import type { SqlDatabaseCredentials } from "@celerity-sdk/sql-database";
91
+
92
+ @Injectable()
93
+ class PrismaService {
94
+ constructor(
95
+ @SqlCredentials() private readonly credentials: SqlDatabaseCredentials,
96
+ ) {}
97
+
98
+ async getDatabaseUrl(): Promise<string> {
99
+ const auth = await this.credentials.getPasswordAuth();
100
+ return auth.url;
101
+ }
102
+ }
103
+ ```
104
+
105
+ ### Multi-resource support
106
+
107
+ When multiple SQL databases are linked, use the resource name to disambiguate:
108
+
109
+ ```typescript
110
+ import { Injectable } from "@celerity-sdk/core";
111
+ import { SqlWriter } from "@celerity-sdk/sql-database";
112
+ import type { Knex } from "knex";
113
+
114
+ @Injectable()
115
+ class AnalyticsService {
116
+ constructor(
117
+ @SqlWriter("analyticsDb") private readonly analytics: Knex,
118
+ @SqlWriter("mainDb") private readonly main: Knex,
119
+ ) {}
120
+ }
121
+ ```
122
+
123
+ For a single linked database, the resource name can be omitted and default tokens are used automatically.
124
+
13
125
  ## Status
14
126
 
15
- This package is a stub:the interface and provider implementations are planned but not yet implemented.
127
+ This package implements credential resolution, Knex.js connection factory, pool management, and DI integration for AWS RDS (PostgreSQL and MySQL). IAM authentication uses a pluggable `TokenProvider` interface, with an `RdsTokenProvider` for AWS. Support for Google Cloud SQL and Azure Database will be added in future releases.
16
128
 
17
129
  ## Part of the Celerity Framework
18
130