@superfunctions/db 0.1.0 โ 0.1.1
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 +12 -59
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
# @superfunctions/db
|
|
2
2
|
|
|
3
|
-
Shared database adapter system for Superfunctions libraries. Provides a unified interface for interacting with databases across multiple ORMs (Drizzle, Prisma, Kysely
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **๐ Multiple ORM Support**: Works with Drizzle, Prisma, Kysely, MongoDB
|
|
8
|
-
- **๐ฏ Type Safe**: Full TypeScript support with strict types
|
|
9
|
-
- **๐ Unified Interface**: Single adapter interface across all ORMs
|
|
10
|
-
- **๐ฆ Namespace Isolation**: Prevent table name conflicts between libraries
|
|
11
|
-
- **โก Progressive Enhancement**: Adapters declare capabilities, libraries adapt accordingly
|
|
12
|
-
- **๐งช Testing Utilities**: Built-in memory adapter and testing tools
|
|
13
|
-
- **๐ง Schema Management**: Version tracking and migration support
|
|
3
|
+
Shared database adapter system for Superfunctions libraries. Provides a unified interface for interacting with databases across multiple ORMs (Drizzle, Prisma, Kysely).
|
|
14
4
|
|
|
15
5
|
## Installation
|
|
16
6
|
|
|
@@ -21,7 +11,6 @@ npm install @superfunctions/db
|
|
|
21
11
|
npm install drizzle-orm # For Drizzle
|
|
22
12
|
npm install @prisma/client # For Prisma
|
|
23
13
|
npm install kysely # For Kysely
|
|
24
|
-
npm install mongodb # For MongoDB
|
|
25
14
|
```
|
|
26
15
|
|
|
27
16
|
## Quick Start
|
|
@@ -29,7 +18,7 @@ npm install mongodb # For MongoDB
|
|
|
29
18
|
### Using with a Library
|
|
30
19
|
|
|
31
20
|
```typescript
|
|
32
|
-
import {
|
|
21
|
+
import { AuthFn } from '@superfunctions/authFn';
|
|
33
22
|
import { memoryAdapter } from '@superfunctions/db/adapters';
|
|
34
23
|
|
|
35
24
|
// Create adapter
|
|
@@ -38,50 +27,19 @@ const adapter = memoryAdapter({
|
|
|
38
27
|
});
|
|
39
28
|
|
|
40
29
|
// Initialize library with adapter
|
|
41
|
-
const
|
|
30
|
+
const authFn = AuthFn({
|
|
42
31
|
database: adapter,
|
|
43
|
-
namespace: '
|
|
32
|
+
namespace: 'authFn'
|
|
44
33
|
});
|
|
45
34
|
|
|
46
35
|
// Use the library
|
|
47
|
-
await
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
36
|
+
await authFn.createUser({
|
|
37
|
+
email: 'user@example.com',
|
|
38
|
+
password: 'password',
|
|
39
|
+
name: 'John Doe',
|
|
51
40
|
});
|
|
52
41
|
```
|
|
53
42
|
|
|
54
|
-
### Creating a Custom Adapter
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
import { createAdapterFactory } from '@superfunctions/db';
|
|
58
|
-
import type { AdapterFactoryOptions } from '@superfunctions/db';
|
|
59
|
-
|
|
60
|
-
export function myCustomAdapter(db: any, config: any) {
|
|
61
|
-
return createAdapterFactory({
|
|
62
|
-
config: {
|
|
63
|
-
adapterId: 'my-custom',
|
|
64
|
-
adapterName: 'My Custom Adapter',
|
|
65
|
-
capabilities: {
|
|
66
|
-
types: {
|
|
67
|
-
json: true,
|
|
68
|
-
dates: true,
|
|
69
|
-
booleans: true,
|
|
70
|
-
// ...
|
|
71
|
-
},
|
|
72
|
-
// ...
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
adapter: (context) => ({
|
|
76
|
-
async create(params) {
|
|
77
|
-
// Implementation
|
|
78
|
-
},
|
|
79
|
-
// ... other methods
|
|
80
|
-
}),
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
```
|
|
84
|
-
|
|
85
43
|
## Core Concepts
|
|
86
44
|
|
|
87
45
|
### Adapter Interface
|
|
@@ -149,12 +107,12 @@ const adapter = memoryAdapter({
|
|
|
149
107
|
});
|
|
150
108
|
|
|
151
109
|
// Library A
|
|
152
|
-
const
|
|
153
|
-
// Tables:
|
|
110
|
+
const authFn = AuthFn({ database: adapter, namespace: 'authFn' });
|
|
111
|
+
// Tables: authFn_users, authFn_sessions, authFn_tokens
|
|
154
112
|
|
|
155
113
|
// Library B
|
|
156
|
-
const
|
|
157
|
-
// Tables:
|
|
114
|
+
const fileFn = FileFn({ database: adapter, namespace: 'fileFn' });
|
|
115
|
+
// Tables: fileFn_files, fileFn_folders
|
|
158
116
|
|
|
159
117
|
// No conflicts!
|
|
160
118
|
```
|
|
@@ -253,9 +211,6 @@ const adapter = kyselyAdapter({
|
|
|
253
211
|
- Upsert (INSERT...ON CONFLICT)
|
|
254
212
|
- Multi-dialect support
|
|
255
213
|
|
|
256
|
-
### MongoDB Adapter (Coming Soon)
|
|
257
|
-
|
|
258
|
-
For MongoDB (planned for v1.1 or community contribution)
|
|
259
214
|
|
|
260
215
|
## Testing
|
|
261
216
|
|
|
@@ -337,5 +292,3 @@ Contributions welcome! See [Contributing Guide](../../CONTRIBUTING.md) for detai
|
|
|
337
292
|
## Related Packages
|
|
338
293
|
|
|
339
294
|
- `@superfunctions/cli` - Schema management and migrations
|
|
340
|
-
- `@superfunctions/sendFn` - Email functionality (example library)
|
|
341
|
-
- `@superfunctions/webFn` - Web scraping (example library)
|