@earth-app/collegedb 1.1.2 → 1.1.4
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 +247 -48
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -9
- package/dist/index.js.map +6 -6
- package/dist/router.d.ts +331 -0
- package/dist/router.d.ts.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -23,6 +23,8 @@ A TypeScript library for **true horizontal scaling** of SQLite-style databases p
|
|
|
23
23
|
- [Multi-Key Shard Mappings](#multi-key-shard-mappings)
|
|
24
24
|
- [Drop-in Replacement for Existing Databases](#drop-in-replacement-for-existing-databases)
|
|
25
25
|
- [Troubleshooting](#troubleshooting)
|
|
26
|
+
- [Cross-Shard Pagination Behavior](#cross-shard-pagination-behavior)
|
|
27
|
+
- [Database Query Best Practices](#database-query-best-practices)
|
|
26
28
|
- [API Reference](#api-reference)
|
|
27
29
|
- [Architecture](#architecture)
|
|
28
30
|
- [Cloudflare Setup](#cloudflare-setup)
|
|
@@ -69,6 +71,7 @@ This allows you to:
|
|
|
69
71
|
- Automatic query routing (primary key to shard mapping)
|
|
70
72
|
- Provider adapters for Redis/Valkey/NuxtHub KV plus PostgreSQL/MySQL/SQLite SQL
|
|
71
73
|
- Drizzle interop through existing SQL providers (`createPostgreSQLProvider`, `createMySQLProvider`, `createSQLiteProvider`)
|
|
74
|
+
- Auto-allocated generated-id inserts via `insert()` and direct-shard inserts via `insertShard()` for AUTOINCREMENT / RETURNING workflows
|
|
72
75
|
- Hyperdrive helpers for PostgreSQL and MySQL
|
|
73
76
|
- Multiple allocation strategies: round-robin, random, hash, location-aware, and mixed read/write strategies
|
|
74
77
|
- Durable Object shard coordination and shard statistics
|
|
@@ -191,18 +194,19 @@ CollegeDB includes a benchmark runner that executes each SQL+KV combination acro
|
|
|
191
194
|
|
|
192
195
|
### Scenario Catalog
|
|
193
196
|
|
|
194
|
-
| Scenario Key | Scenario | What Happens
|
|
195
|
-
| ----------------- | -------------------------------- |
|
|
196
|
-
| basic_crud | Basic CRUD round-trip | Insert, read, update, and delete a user via routed queries.
|
|
197
|
-
| advanced_usage | Advanced lookup workflow | Writes user+post, adds lookup aliases, then validates join and alias-based lookup.
|
|
198
|
-
| migration_mapping | Migration-style mapping creation | Inserts legacy records on a fixed shard, then builds shard mappings in batch and validates routing.
|
|
199
|
-
| bulk_crud | Bulk CRUD pressure | Performs bulk inserts, half updates, and full delete sweep, then validates shard-wide totals.
|
|
200
|
-
|
|
|
201
|
-
|
|
|
202
|
-
|
|
|
203
|
-
|
|
|
204
|
-
|
|
|
205
|
-
|
|
|
197
|
+
| Scenario Key | Scenario | What Happens | Workload Per Run |
|
|
198
|
+
| ----------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
|
|
199
|
+
| basic_crud | Basic CRUD round-trip | Insert, read, update, and delete a user via routed queries. | 20 iterations; 4 routed SQL ops per iteration |
|
|
200
|
+
| advanced_usage | Advanced lookup workflow | Writes user+post, adds lookup aliases, then validates join and alias-based lookup. | 15 iterations; ~5 routed SQL ops + KV lookup-key updates per iteration |
|
|
201
|
+
| migration_mapping | Migration-style mapping creation | Inserts legacy records on a fixed shard, then builds shard mappings in batch and validates routing. | 10 iterations; 20 legacy records mapped per iteration |
|
|
202
|
+
| bulk_crud | Bulk CRUD pressure | Performs bulk inserts, half updates, and full delete sweep, then validates shard-wide totals. | 7 iterations; 160 inserts + 80 updates + 160 deletes per iteration |
|
|
203
|
+
| auto_increment | Auto-generated primary keys | Inserts rows with generated ids on an automatically selected shard, captures the generated key, then validates routed readback. | 6 iterations; insert + generated-id readback per iteration |
|
|
204
|
+
| indexing | Indexed query scan | Creates an index on posts(user_id) and repeatedly queries the indexed path. | 15 iterations after warmup dataset build |
|
|
205
|
+
| metadata_fetch | Metadata inspection | Reads table metadata/introspection rows from one shard. | 14 iterations; 1 metadata query per iteration |
|
|
206
|
+
| pragma_or_info | PRAGMA / server info | Runs provider-specific PRAGMA/info query to sample low-level metadata latency. | 14 iterations; 1 pragma/info query per iteration |
|
|
207
|
+
| counting | Cross-shard counting | Counts users across all shards to measure fanout aggregation overhead. | 14 iterations; all-shard count aggregation per iteration |
|
|
208
|
+
| shard_fanout | Shard fanout query | Runs query fanout to all shards and aggregates shard-level responses. | 14 iterations; 1 all-shards query per iteration |
|
|
209
|
+
| reassignment | Shard reassignment flow | Creates a record, reassigns it to another shard, and verifies routed reads still succeed. | 10 iterations; insert + reassignment + verification per iteration |
|
|
206
210
|
|
|
207
211
|
### Report Matrices
|
|
208
212
|
|
|
@@ -437,6 +441,7 @@ Benchmark coverage includes:
|
|
|
437
441
|
- advanced lookup/routing workflows
|
|
438
442
|
- migration-style mapping creation
|
|
439
443
|
- bulk CRUD
|
|
444
|
+
- auto-generated primary key inserts and readback
|
|
440
445
|
- indexing queries
|
|
441
446
|
- metadata fetch
|
|
442
447
|
- pragma/info queries (provider-specific)
|
|
@@ -570,6 +575,67 @@ This approach provides:
|
|
|
570
575
|
- **Optimal read performance**: Queries use `hash` strategy for consistent, high-performance routing
|
|
571
576
|
- **Flexibility**: Each operation type can use the most appropriate routing strategy
|
|
572
577
|
|
|
578
|
+
### Auto-Generated Primary Keys
|
|
579
|
+
|
|
580
|
+
When your table assigns the primary key during insert, use `insert()` for the automatic shard-allocation path or `insertShard()` when you already know the target shard. Both helpers capture the generated id from provider metadata or `RETURNING` rows, then store the generated-id mapping so the normal routed `first()` / `all()` helpers can read the row back.
|
|
581
|
+
|
|
582
|
+
```typescript
|
|
583
|
+
import { first, insert, insertShard } from '@earth-app/collegedb';
|
|
584
|
+
|
|
585
|
+
// SQLite / D1
|
|
586
|
+
await createSchema(
|
|
587
|
+
env['db-east'],
|
|
588
|
+
`
|
|
589
|
+
CREATE TABLE IF NOT EXISTS auto_users (
|
|
590
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
591
|
+
name TEXT NOT NULL,
|
|
592
|
+
email TEXT UNIQUE,
|
|
593
|
+
created_at INTEGER
|
|
594
|
+
)
|
|
595
|
+
`
|
|
596
|
+
);
|
|
597
|
+
|
|
598
|
+
const created = await insert('INSERT INTO auto_users (name, email, created_at) VALUES (?, ?, ?)', ['Ada', 'ada@example.com', Date.now()]);
|
|
599
|
+
|
|
600
|
+
const row = await first(String(created.generatedId), 'SELECT * FROM auto_users WHERE id = ?', [created.generatedId]);
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
```typescript
|
|
604
|
+
// Direct shard insert when you want to pin the write to a specific shard
|
|
605
|
+
const directCreated = await insertShard('db-east', 'INSERT INTO auto_users (name, email, created_at) VALUES (?, ?, ?)', [
|
|
606
|
+
'Ada',
|
|
607
|
+
'ada@example.com',
|
|
608
|
+
Date.now()
|
|
609
|
+
]);
|
|
610
|
+
|
|
611
|
+
console.log(directCreated.generatedId);
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
```typescript
|
|
615
|
+
// PostgreSQL / MySQL 8.0.19+ RETURNING path
|
|
616
|
+
await createSchema(
|
|
617
|
+
env['db-east'],
|
|
618
|
+
`
|
|
619
|
+
CREATE TABLE IF NOT EXISTS auto_users (
|
|
620
|
+
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
|
621
|
+
name VARCHAR(255) NOT NULL,
|
|
622
|
+
email VARCHAR(255) UNIQUE,
|
|
623
|
+
created_at BIGINT
|
|
624
|
+
)
|
|
625
|
+
`
|
|
626
|
+
);
|
|
627
|
+
|
|
628
|
+
const created = await insert('INSERT INTO auto_users (name, email, created_at) VALUES (?, ?, ?) RETURNING id', [
|
|
629
|
+
'Ada',
|
|
630
|
+
'ada@example.com',
|
|
631
|
+
Date.now()
|
|
632
|
+
]);
|
|
633
|
+
|
|
634
|
+
const row = await first(String(created.generatedId), 'SELECT * FROM auto_users WHERE id = ?', [created.generatedId]);
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
If your SQL dialect uses `RETURNING`, include it in the insert statement. The helper will use the returned row instead of provider metadata when present.
|
|
638
|
+
|
|
573
639
|
## Multi-Key Shard Mappings
|
|
574
640
|
|
|
575
641
|
CollegeDB supports **multiple lookup keys** for the same record, allowing you to query by username, email, ID, or any unique identifier. Keys are automatically hashed with SHA-256 for security and privacy.
|
|
@@ -616,6 +682,22 @@ await mapper.addLookupKeys('user-456', ['email:jane@example.com', 'username:jane
|
|
|
616
682
|
const user = await first('email:jane@example.com', 'SELECT * FROM users WHERE email = ?', ['jane@example.com']);
|
|
617
683
|
```
|
|
618
684
|
|
|
685
|
+
### Lookup-Key Read Helpers With Fanout Fallback
|
|
686
|
+
|
|
687
|
+
When you query by a secondary key and want safe behavior even when a lookup mapping is missing or stale, use the router-level helpers:
|
|
688
|
+
|
|
689
|
+
```typescript
|
|
690
|
+
import { allByLookupKey, firstByLookupKey } from '@earth-app/collegedb';
|
|
691
|
+
|
|
692
|
+
// Uses lookup-key mapping when present, then falls back to all-shard fanout if needed
|
|
693
|
+
const user = await firstByLookupKey('email:john@example.com', 'SELECT * FROM users WHERE email = ? LIMIT 1', ['john@example.com']);
|
|
694
|
+
|
|
695
|
+
// Same resolution flow, but returns merged row sets
|
|
696
|
+
const matches = await allByLookupKey('username:john_doe', 'SELECT id, username FROM users WHERE username = ?', ['john_doe']);
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
This avoids accidentally creating a new primary-key mapping for secondary identifiers while still returning results when mappings are unavailable.
|
|
700
|
+
|
|
619
701
|
### Security and Privacy
|
|
620
702
|
|
|
621
703
|
**SHA-256 Hashing (Enabled by Default)**: Sensitive data like emails are hashed before being stored as KV keys, protecting user privacy:
|
|
@@ -908,28 +990,140 @@ for (const [table, pkColumn] of Object.entries(customIntegration)) {
|
|
|
908
990
|
}
|
|
909
991
|
```
|
|
910
992
|
|
|
993
|
+
## Cross-Shard Pagination Behavior
|
|
994
|
+
|
|
995
|
+
`allAllShards` and `firstAllShards` execute the exact SQL on each shard independently. That means SQL `LIMIT`/`OFFSET` applies per shard, not globally.
|
|
996
|
+
|
|
997
|
+
```typescript
|
|
998
|
+
// With two shards, this can return up to 20 total rows (10 per shard)
|
|
999
|
+
const perShard = await allAllShards('SELECT * FROM posts ORDER BY created_at DESC LIMIT 10');
|
|
1000
|
+
```
|
|
1001
|
+
|
|
1002
|
+
If you need true global merge/sort/pagination across all shard results, use `allAllShardsGlobal` / `firstAllShardsGlobal` and pass sort/pagination options to the library:
|
|
1003
|
+
|
|
1004
|
+
```typescript
|
|
1005
|
+
import { allAllShardsGlobal, firstAllShardsGlobal } from '@earth-app/collegedb';
|
|
1006
|
+
|
|
1007
|
+
const page = await allAllShardsGlobal<{ id: string; created_at: number }>('SELECT id, created_at FROM posts', [], {
|
|
1008
|
+
sortBy: 'created_at',
|
|
1009
|
+
sortDirection: 'desc',
|
|
1010
|
+
offset: 20,
|
|
1011
|
+
limit: 10
|
|
1012
|
+
});
|
|
1013
|
+
|
|
1014
|
+
const newest = await firstAllShardsGlobal<{ id: string; created_at: number }>('SELECT id, created_at FROM posts', [], {
|
|
1015
|
+
sortBy: 'created_at',
|
|
1016
|
+
sortDirection: 'desc'
|
|
1017
|
+
});
|
|
1018
|
+
```
|
|
1019
|
+
|
|
1020
|
+
## Database Query Best Practices
|
|
1021
|
+
|
|
1022
|
+
### Use Library Utility Operations for DDL and Inspection
|
|
1023
|
+
|
|
1024
|
+
CollegeDB now exposes utility helpers for operational tasks that need shard awareness:
|
|
1025
|
+
|
|
1026
|
+
```typescript
|
|
1027
|
+
import { countAllShards, explainAllShards, getDatabaseSizesAllShards, indexAllShards } from '@earth-app/collegedb';
|
|
1028
|
+
|
|
1029
|
+
// Create index across all shards
|
|
1030
|
+
await indexAllShards('posts', [{ name: 'user_id' }, { name: 'created_at', order: 'DESC' }], {
|
|
1031
|
+
ifNotExists: true
|
|
1032
|
+
});
|
|
1033
|
+
|
|
1034
|
+
// Inspect query plan across all shards
|
|
1035
|
+
const plans = await explainAllShards('SELECT * FROM posts WHERE user_id = ? ORDER BY created_at DESC LIMIT 20', ['user-123']);
|
|
1036
|
+
|
|
1037
|
+
// Count rows globally
|
|
1038
|
+
const counts = await countAllShards('posts');
|
|
1039
|
+
|
|
1040
|
+
// Get per-shard size measurements
|
|
1041
|
+
const sizes = await getDatabaseSizesAllShards();
|
|
1042
|
+
```
|
|
1043
|
+
|
|
1044
|
+
Recommended pattern:
|
|
1045
|
+
|
|
1046
|
+
- Use `indexAllShards` for schema/index consistency.
|
|
1047
|
+
- Use `explain`/`explainAllShards` before adding indexes or changing query shapes.
|
|
1048
|
+
- Use `countAllShards` and `getDatabaseSizesAllShards` for operational dashboards and rebalancing thresholds.
|
|
1049
|
+
|
|
1050
|
+
### Create Targeted Indexes
|
|
1051
|
+
|
|
1052
|
+
```sql
|
|
1053
|
+
CREATE INDEX IF NOT EXISTS idx_posts_user_id_created_at ON posts(user_id, created_at DESC);
|
|
1054
|
+
CREATE INDEX IF NOT EXISTS idx_users_email ON users(email);
|
|
1055
|
+
```
|
|
1056
|
+
|
|
1057
|
+
### Inspect Query Plans and Statistics
|
|
1058
|
+
|
|
1059
|
+
```sql
|
|
1060
|
+
EXPLAIN QUERY PLAN SELECT * FROM posts WHERE user_id = ? ORDER BY created_at DESC LIMIT 20;
|
|
1061
|
+
PRAGMA optimize;
|
|
1062
|
+
ANALYZE;
|
|
1063
|
+
```
|
|
1064
|
+
|
|
1065
|
+
### Use Bound Parameters (SQL Injection Protection)
|
|
1066
|
+
|
|
1067
|
+
```typescript
|
|
1068
|
+
// Safe: parameterized query
|
|
1069
|
+
await first('user-123', 'SELECT * FROM users WHERE email = ?', [email]);
|
|
1070
|
+
|
|
1071
|
+
// Avoid string interpolation with user input
|
|
1072
|
+
// BAD: `... WHERE email = '${email}'`
|
|
1073
|
+
```
|
|
1074
|
+
|
|
1075
|
+
### Design Search for Scale
|
|
1076
|
+
|
|
1077
|
+
- Exact-match or prefix search fields should be indexed.
|
|
1078
|
+
- Prefer bounded result sets (`LIMIT`) and stable sorting.
|
|
1079
|
+
- For global search pages, pair lightweight per-shard SQL with `allAllShardsGlobal` for final merge/sort/pagination.
|
|
1080
|
+
|
|
1081
|
+
### Pagination Guidance
|
|
1082
|
+
|
|
1083
|
+
- For routed single-key reads (`first`, `all`), SQL pagination is naturally shard-local and predictable.
|
|
1084
|
+
- For fanout (`allAllShards`, `firstAllShards`), SQL pagination is per-shard.
|
|
1085
|
+
- For user-facing global pages, use `allAllShardsGlobal` so offset/limit apply once after merge.
|
|
1086
|
+
|
|
911
1087
|
## API Reference
|
|
912
1088
|
|
|
913
|
-
| Function
|
|
914
|
-
|
|
|
915
|
-
| `collegedb(config, callback)`
|
|
916
|
-
| `initialize(config)`
|
|
917
|
-
| `createSchema(db, schema)`
|
|
918
|
-
| `prepare(key, sql)`
|
|
919
|
-
| `run(key, sql, bindings)`
|
|
920
|
-
| `
|
|
921
|
-
| `
|
|
922
|
-
| `
|
|
923
|
-
| `
|
|
924
|
-
| `
|
|
925
|
-
| `
|
|
926
|
-
| `
|
|
927
|
-
| `
|
|
928
|
-
| `
|
|
929
|
-
| `
|
|
930
|
-
| `
|
|
931
|
-
| `
|
|
932
|
-
| `
|
|
1089
|
+
| Function | Description | Parameters |
|
|
1090
|
+
| ------------------------------------------------- | ---------------------------------------------------------------------- | ------------------------------------------------------------------ |
|
|
1091
|
+
| `collegedb(config, callback)` | Initialize CollegeDB, then run a callback | `CollegeDBConfig, () => T` |
|
|
1092
|
+
| `initialize(config)` | Initialize CollegeDB with configuration | `CollegeDBConfig` |
|
|
1093
|
+
| `createSchema(db, schema)` | Create schema on a shard database | `SQLDatabase, string` |
|
|
1094
|
+
| `prepare(key, sql)` | Prepare a SQL statement for execution | `string, string` |
|
|
1095
|
+
| `run(key, sql, bindings)` | Execute a SQL query with primary key routing | `string, string, any[]` |
|
|
1096
|
+
| `insert(sql, bindings)` | Insert on an automatically selected shard and capture the generated id | `string, any[]` |
|
|
1097
|
+
| `insertShard(shard, sql, bindings)` | Insert directly on a specific shard and capture the generated id | `string, string, any[]` |
|
|
1098
|
+
| `first(key, sql, bindings)` | Execute a SQL query and return first result | `string, string, any[]` |
|
|
1099
|
+
| `all(key, sql, bindings)` | Execute a SQL query and return all results | `string, string, any[]` |
|
|
1100
|
+
| `index(key, table, columns, options)` | Create an index on routed shard | `string, string, string or index-column array, CreateIndexOptions` |
|
|
1101
|
+
| `indexShard(shard, table, columns, options)` | Create an index on one shard | `string, string, string or index-column array, CreateIndexOptions` |
|
|
1102
|
+
| `indexAllShards(table, columns, options)` | Create an index on all shards | `string, string or index-column array, CreateIndexOptions` |
|
|
1103
|
+
| `firstByLookupKey(key, sql, bindings, batchSize)` | Resolve secondary-key mapping, fallback to fanout | `string, string, any[], number` |
|
|
1104
|
+
| `allByLookupKey(key, sql, bindings, batchSize)` | Resolve secondary-key mapping, fallback to fanout | `string, string, any[], number` |
|
|
1105
|
+
| `runShard(shard, sql, bindings)` | Execute a query directly on a specific shard | `string, string, any[]` |
|
|
1106
|
+
| `allShard(shard, sql, bindings)` | Execute a query on specific shard, return all results | `string, string, any[]` |
|
|
1107
|
+
| `firstShard(shard, sql, bindings)` | Execute a query on specific shard, return first result | `string, string, any[]` |
|
|
1108
|
+
| `explain(key, sql, bindings, options)` | Inspect query plan on routed shard | `string, string, any[], ExplainOptions` |
|
|
1109
|
+
| `explainShard(shard, sql, bindings, options)` | Inspect query plan on one shard | `string, string, any[], ExplainOptions` |
|
|
1110
|
+
| `explainAllShards(sql, bindings, options)` | Inspect query plan on all shards | `string, any[], ExplainOptions` |
|
|
1111
|
+
| `count(key, table)` | Count rows on routed shard | `string, string` |
|
|
1112
|
+
| `countShard(shard, table)` | Count rows on a specific shard | `string, string` |
|
|
1113
|
+
| `countAllShards(table, batchSize)` | Count rows per shard and global total | `string, number` |
|
|
1114
|
+
| `runAllShards(sql, bindings, batchSize)` | Execute query on all shards | `string, any[], number` |
|
|
1115
|
+
| `allAllShards(sql, bindings, batchSize)` | Execute query on all shards (SQL pagination applies per shard) | `string, any[], number` |
|
|
1116
|
+
| `firstAllShards(sql, bindings, batchSize)` | Execute query on all shards, return first row per shard | `string, any[], number` |
|
|
1117
|
+
| `allAllShardsGlobal(sql, bindings, options)` | Execute query on all shards, then globally merge/sort/paginate | `string, any[], GlobalAllShardsOptions` |
|
|
1118
|
+
| `firstAllShardsGlobal(sql, bindings, options)` | Return first row after global merge/sort/paginate | `string, any[], GlobalAllShardsOptions` |
|
|
1119
|
+
| `reassignShard(key, newShard)` | Move primary key to different shard | `string, string` |
|
|
1120
|
+
| `listKnownShards()` | Get list of available shards | `void` |
|
|
1121
|
+
| `getShardStats()` | Get statistics for all shards | `void` |
|
|
1122
|
+
| `getDatabaseSizeForKey(key)` | Get size of key-routed shard in bytes | `string` |
|
|
1123
|
+
| `getDatabaseSizeForShard(shard)` | Get size of a specific shard in bytes | `string` |
|
|
1124
|
+
| `getDatabaseSizesAllShards(batchSize)` | Get per-shard size data | `number` |
|
|
1125
|
+
| `getTotalDatabaseSize(batchSize)` | Get total size across all shards | `number` |
|
|
1126
|
+
| `flush()` | Clear all shard mappings (development only) | `void` |
|
|
933
1127
|
|
|
934
1128
|
### Provider Adapter Functions
|
|
935
1129
|
|
|
@@ -1192,22 +1386,27 @@ const config: CollegeDBConfig = {
|
|
|
1192
1386
|
|
|
1193
1387
|
CollegeDB exports TypeScript types for better development experience and type safety:
|
|
1194
1388
|
|
|
1195
|
-
| Type | Description | Example
|
|
1196
|
-
| ----------------------- | ------------------------------ |
|
|
1197
|
-
| `CollegeDBConfig` | Main configuration object | `{ kv, shards, strategy }`
|
|
1198
|
-
| `KVStorage` | Provider-agnostic KV contract | `createRedisKVProvider(redisClient)`
|
|
1199
|
-
| `SQLDatabase` | Provider-agnostic SQL contract | `createPostgreSQLProvider(pgPool)`
|
|
1200
|
-
| `NuxtHubKVLike` | NuxtHub/Unstorage KV contract | `createNuxtHubKVProvider(kv)`
|
|
1201
|
-
| `DrizzleClientLike` | Minimal Drizzle DB contract | `createPostgreSQLProvider(drizzleDb, sql)`
|
|
1202
|
-
| `DrizzleSqlTagLike` | Drizzle SQL tag contract | `createSQLiteProvider(drizzleDb, sql)`
|
|
1203
|
-
| `QueryResult` | Standard query response shape | `{ success, results, meta }`
|
|
1204
|
-
| `QueryResultMeta` | Query execution metadata | `{ duration, changes?, last_row_id? }`
|
|
1205
|
-
| `ShardingStrategy` | Single strategy options | `'hash' \| 'location' \| 'round-robin' \| 'random'`
|
|
1206
|
-
| `MixedShardingStrategy` | Mixed strategy configuration | `{ read: 'hash', write: 'location' }`
|
|
1207
|
-
| `OperationType` | Database operation types | `'read' \| 'write'`
|
|
1208
|
-
| `D1Region` | Cloudflare D1 regions | `'wnam' \| 'enam' \| 'weur' \| ...`
|
|
1209
|
-
| `ShardLocation` | Geographic shard configuration | `{ region: 'wnam', priority: 2 }`
|
|
1210
|
-
| `ShardStats` | Shard usage statistics | `{ binding: 'db-east', count: 1542 }`
|
|
1389
|
+
| Type | Description | Example |
|
|
1390
|
+
| ----------------------- | ------------------------------ | ----------------------------------------------------- |
|
|
1391
|
+
| `CollegeDBConfig` | Main configuration object | `{ kv, shards, strategy }` |
|
|
1392
|
+
| `KVStorage` | Provider-agnostic KV contract | `createRedisKVProvider(redisClient)` |
|
|
1393
|
+
| `SQLDatabase` | Provider-agnostic SQL contract | `createPostgreSQLProvider(pgPool)` |
|
|
1394
|
+
| `NuxtHubKVLike` | NuxtHub/Unstorage KV contract | `createNuxtHubKVProvider(kv)` |
|
|
1395
|
+
| `DrizzleClientLike` | Minimal Drizzle DB contract | `createPostgreSQLProvider(drizzleDb, sql)` |
|
|
1396
|
+
| `DrizzleSqlTagLike` | Drizzle SQL tag contract | `createSQLiteProvider(drizzleDb, sql)` |
|
|
1397
|
+
| `QueryResult` | Standard query response shape | `{ success, results, meta }` |
|
|
1398
|
+
| `QueryResultMeta` | Query execution metadata | `{ duration, changes?, last_row_id? }` |
|
|
1399
|
+
| `ShardingStrategy` | Single strategy options | `'hash' \| 'location' \| 'round-robin' \| 'random'` |
|
|
1400
|
+
| `MixedShardingStrategy` | Mixed strategy configuration | `{ read: 'hash', write: 'location' }` |
|
|
1401
|
+
| `OperationType` | Database operation types | `'read' \| 'write'` |
|
|
1402
|
+
| `D1Region` | Cloudflare D1 regions | `'wnam' \| 'enam' \| 'weur' \| ...` |
|
|
1403
|
+
| `ShardLocation` | Geographic shard configuration | `{ region: 'wnam', priority: 2 }` |
|
|
1404
|
+
| `ShardStats` | Shard usage statistics | `{ binding: 'db-east', count: 1542 }` |
|
|
1405
|
+
| `IndexColumnDefinition` | Index column definition | `{ name: 'created_at', order: 'DESC' }` |
|
|
1406
|
+
| `CreateIndexOptions` | Index creation options | `{ ifNotExists: true, unique: false }` |
|
|
1407
|
+
| `ExplainOptions` | Explain mode options | `{ mode: 'query-plan' }` |
|
|
1408
|
+
| `ShardTableCount` | Per-shard row-count result | `{ shard: 'db-east', count: 100, success: true }` |
|
|
1409
|
+
| `ShardSizeResult` | Per-shard size result | `{ shard: 'db-east', size: 10485760, success: true }` |
|
|
1211
1410
|
|
|
1212
1411
|
#### Mixed Strategy Configuration
|
|
1213
1412
|
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* @author Gregory Mitchell
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
export { all, allAllShards, allShard, collegedb, createSchema, first, firstAllShards, firstShard, flush, getClosestRegionFromIP, getDatabaseSizeForShard, getShardStats, initialize, initializeAsync, listKnownShards, prepare, reassignShard, resetConfig, run, runAllShards, runShard } from './router';
|
|
11
|
+
export { all, allAllShards, allAllShardsGlobal, allByLookupKey, allShard, collegedb, count, countAllShards, countShard, createSchema, explain, explainAllShards, explainShard, first, firstAllShards, firstAllShardsGlobal, firstByLookupKey, firstShard, flush, getClosestRegionFromIP, getDatabaseSizeForKey, getDatabaseSizeForShard, getDatabaseSizesAllShards, getShardStats, getTotalDatabaseSize, index, indexAllShards, indexShard, initialize, initializeAsync, insert, insertShard, listKnownShards, prepare, reassignShard, resetConfig, run, runAllShards, runShard } from './router';
|
|
12
|
+
export type { CreateIndexOptions, ExplainOptions, GlobalAllShardsOptions, IndexColumnDefinition, InsertResult, ShardSizeResult, ShardTableCount } from './router';
|
|
12
13
|
export { ShardCoordinator } from './durable';
|
|
13
14
|
export { CollegeDBError } from './errors';
|
|
14
15
|
export { KVShardMapper } from './kvmap';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EACN,GAAG,EACH,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,KAAK,EACL,cAAc,EACd,UAAU,EACV,KAAK,EACL,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,UAAU,EACV,eAAe,EACf,eAAe,EACf,OAAO,EACP,aAAa,EACb,WAAW,EACX,GAAG,EACH,YAAY,EACZ,QAAQ,EACR,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,EACN,wBAAwB,EACxB,6BAA6B,EAC7B,gCAAgC,EAChC,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,WAAW,EACX,aAAa,EACb,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,EACjC,KAAK,+BAA+B,EACpC,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACN,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,wBAAwB,EACxB,6BAA6B,EAC7B,wBAAwB,EACxB,2BAA2B,EAC3B,kCAAkC,EAClC,UAAU,EACV,yBAAyB,EACzB,UAAU,EACV,aAAa,EACb,YAAY,EACZ,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACX,eAAe,EACf,QAAQ,EACR,GAAG,EACH,YAAY,EACZ,SAAS,EACT,qBAAqB,EACrB,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,WAAW,EACX,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EACN,GAAG,EACH,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACR,SAAS,EACT,KAAK,EACL,cAAc,EACd,UAAU,EACV,YAAY,EACZ,OAAO,EACP,gBAAgB,EAChB,YAAY,EACZ,KAAK,EACL,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,UAAU,EACV,KAAK,EACL,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACvB,yBAAyB,EACzB,aAAa,EACb,oBAAoB,EACpB,KAAK,EACL,cAAc,EACd,UAAU,EACV,UAAU,EACV,eAAe,EACf,MAAM,EACN,WAAW,EACX,eAAe,EACf,OAAO,EACP,aAAa,EACb,WAAW,EACX,GAAG,EACH,YAAY,EACZ,QAAQ,EACR,MAAM,UAAU,CAAC;AAElB,YAAY,EACX,kBAAkB,EAClB,cAAc,EACd,sBAAsB,EACtB,qBAAqB,EACrB,YAAY,EACZ,eAAe,EACf,eAAe,EACf,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,EACN,wBAAwB,EACxB,6BAA6B,EAC7B,gCAAgC,EAChC,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,WAAW,EACX,aAAa,EACb,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,EACjC,KAAK,+BAA+B,EACpC,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACN,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,wBAAwB,EACxB,6BAA6B,EAC7B,wBAAwB,EACxB,2BAA2B,EAC3B,kCAAkC,EAClC,UAAU,EACV,yBAAyB,EACzB,UAAU,EACV,aAAa,EACb,YAAY,EACZ,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACX,eAAe,EACf,QAAQ,EACR,GAAG,EACH,YAAY,EACZ,SAAS,EACT,qBAAqB,EACrB,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,WAAW,EACX,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,MAAM,SAAS,CAAC"}
|