@plyaz/db 0.0.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.
Files changed (118) hide show
  1. package/README.md +169 -0
  2. package/dist/adapters/drizzle/DrizzleAdapter.d.ts +269 -0
  3. package/dist/adapters/drizzle/DrizzleAdapter.d.ts.map +1 -0
  4. package/dist/adapters/index.d.ts +20 -0
  5. package/dist/adapters/index.d.ts.map +1 -0
  6. package/dist/adapters/sql/SQLAdapter.d.ts +282 -0
  7. package/dist/adapters/sql/SQLAdapter.d.ts.map +1 -0
  8. package/dist/adapters/supabase/SupabaseAdapter.d.ts +305 -0
  9. package/dist/adapters/supabase/SupabaseAdapter.d.ts.map +1 -0
  10. package/dist/advanced/backup/BackupService.d.ts +159 -0
  11. package/dist/advanced/backup/BackupService.d.ts.map +1 -0
  12. package/dist/advanced/backup/index.d.ts +2 -0
  13. package/dist/advanced/backup/index.d.ts.map +1 -0
  14. package/dist/advanced/caching/CacheEvict.decorator.d.ts +3 -0
  15. package/dist/advanced/caching/CacheEvict.decorator.d.ts.map +1 -0
  16. package/dist/advanced/caching/Cacheable.decorator.d.ts +99 -0
  17. package/dist/advanced/caching/Cacheable.decorator.d.ts.map +1 -0
  18. package/dist/advanced/caching/RedisCache.d.ts +417 -0
  19. package/dist/advanced/caching/RedisCache.d.ts.map +1 -0
  20. package/dist/advanced/caching/index.d.ts +4 -0
  21. package/dist/advanced/caching/index.d.ts.map +1 -0
  22. package/dist/advanced/connection-pool/DynamicPool.d.ts +234 -0
  23. package/dist/advanced/connection-pool/DynamicPool.d.ts.map +1 -0
  24. package/dist/advanced/connection-pool/index.d.ts +2 -0
  25. package/dist/advanced/connection-pool/index.d.ts.map +1 -0
  26. package/dist/advanced/index.d.ts +8 -0
  27. package/dist/advanced/index.d.ts.map +1 -0
  28. package/dist/advanced/monitoring/AlertManager.d.ts +72 -0
  29. package/dist/advanced/monitoring/AlertManager.d.ts.map +1 -0
  30. package/dist/advanced/monitoring/MetricsCollector.d.ts +81 -0
  31. package/dist/advanced/monitoring/MetricsCollector.d.ts.map +1 -0
  32. package/dist/advanced/monitoring/index.d.ts +3 -0
  33. package/dist/advanced/monitoring/index.d.ts.map +1 -0
  34. package/dist/advanced/multi-tenancy/TenantContext.d.ts +52 -0
  35. package/dist/advanced/multi-tenancy/TenantContext.d.ts.map +1 -0
  36. package/dist/advanced/multi-tenancy/TenantRepository.d.ts +292 -0
  37. package/dist/advanced/multi-tenancy/TenantRepository.d.ts.map +1 -0
  38. package/dist/advanced/multi-tenancy/index.d.ts +3 -0
  39. package/dist/advanced/multi-tenancy/index.d.ts.map +1 -0
  40. package/dist/advanced/read-replica/ReadReplicaAdapter.d.ts +516 -0
  41. package/dist/advanced/read-replica/ReadReplicaAdapter.d.ts.map +1 -0
  42. package/dist/advanced/read-replica/ReadReplicaManager.d.ts +68 -0
  43. package/dist/advanced/read-replica/ReadReplicaManager.d.ts.map +1 -0
  44. package/dist/advanced/read-replica/UseReplica.decorator.d.ts +24 -0
  45. package/dist/advanced/read-replica/UseReplica.decorator.d.ts.map +1 -0
  46. package/dist/advanced/read-replica/index.d.ts +3 -0
  47. package/dist/advanced/read-replica/index.d.ts.map +1 -0
  48. package/dist/advanced/sharding/ShardKey.d.ts +80 -0
  49. package/dist/advanced/sharding/ShardKey.d.ts.map +1 -0
  50. package/dist/advanced/sharding/ShardRouter.d.ts +66 -0
  51. package/dist/advanced/sharding/ShardRouter.d.ts.map +1 -0
  52. package/dist/advanced/sharding/index.d.ts +3 -0
  53. package/dist/advanced/sharding/index.d.ts.map +1 -0
  54. package/dist/builder/query/index.d.ts +7 -0
  55. package/dist/builder/query/index.d.ts.map +1 -0
  56. package/dist/builder/query/orm.d.ts +22 -0
  57. package/dist/builder/query/orm.d.ts.map +1 -0
  58. package/dist/builder/query/sql.d.ts +29 -0
  59. package/dist/builder/query/sql.d.ts.map +1 -0
  60. package/dist/extensions/AuditExtension.d.ts +468 -0
  61. package/dist/extensions/AuditExtension.d.ts.map +1 -0
  62. package/dist/extensions/CachingAdapter.d.ts +451 -0
  63. package/dist/extensions/CachingAdapter.d.ts.map +1 -0
  64. package/dist/extensions/EncryptionExtension.d.ts +95 -0
  65. package/dist/extensions/EncryptionExtension.d.ts.map +1 -0
  66. package/dist/extensions/ReadReplicaAdapter.d.ts +32 -0
  67. package/dist/extensions/ReadReplicaAdapter.d.ts.map +1 -0
  68. package/dist/extensions/SoftDeleteExtension.d.ts +430 -0
  69. package/dist/extensions/SoftDeleteExtension.d.ts.map +1 -0
  70. package/dist/extensions/index.d.ts +79 -0
  71. package/dist/extensions/index.d.ts.map +1 -0
  72. package/dist/factory/AdapterFactory.d.ts +111 -0
  73. package/dist/factory/AdapterFactory.d.ts.map +1 -0
  74. package/dist/factory/createDatabaseService.d.ts +121 -0
  75. package/dist/factory/createDatabaseService.d.ts.map +1 -0
  76. package/dist/index.cjs +8518 -0
  77. package/dist/index.cjs.map +1 -0
  78. package/dist/index.d.ts +19 -0
  79. package/dist/index.d.ts.map +1 -0
  80. package/dist/index.mjs +8480 -0
  81. package/dist/index.mjs.map +1 -0
  82. package/dist/repository/BaseRepository.d.ts +209 -0
  83. package/dist/repository/BaseRepository.d.ts.map +1 -0
  84. package/dist/repository/index.d.ts +80 -0
  85. package/dist/repository/index.d.ts.map +1 -0
  86. package/dist/security/index.cjs +118 -0
  87. package/dist/security/index.cjs.map +1 -0
  88. package/dist/security/index.d.ts +3 -0
  89. package/dist/security/index.d.ts.map +1 -0
  90. package/dist/security/index.mjs +114 -0
  91. package/dist/security/index.mjs.map +1 -0
  92. package/dist/security/sanitizers/html.sanitizer.d.ts +31 -0
  93. package/dist/security/sanitizers/html.sanitizer.d.ts.map +1 -0
  94. package/dist/security/serializers/DataValidation.d.ts +34 -0
  95. package/dist/security/serializers/DataValidation.d.ts.map +1 -0
  96. package/dist/service/DatabaseService.d.ts +136 -0
  97. package/dist/service/DatabaseService.d.ts.map +1 -0
  98. package/dist/service/EventEmitter.d.ts +110 -0
  99. package/dist/service/EventEmitter.d.ts.map +1 -0
  100. package/dist/service/HealthManager.d.ts +166 -0
  101. package/dist/service/HealthManager.d.ts.map +1 -0
  102. package/dist/utils/ConfigMerger.d.ts +227 -0
  103. package/dist/utils/ConfigMerger.d.ts.map +1 -0
  104. package/dist/utils/databaseResultHelpers.d.ts +98 -0
  105. package/dist/utils/databaseResultHelpers.d.ts.map +1 -0
  106. package/dist/utils/index.d.ts +7 -0
  107. package/dist/utils/index.d.ts.map +1 -0
  108. package/dist/utils/normalizeDetails.d.ts +111 -0
  109. package/dist/utils/normalizeDetails.d.ts.map +1 -0
  110. package/dist/utils/pagination.d.ts +77 -0
  111. package/dist/utils/pagination.d.ts.map +1 -0
  112. package/dist/utils/regex.d.ts +199 -0
  113. package/dist/utils/regex.d.ts.map +1 -0
  114. package/dist/utils/typeGuards.d.ts +57 -0
  115. package/dist/utils/typeGuards.d.ts.map +1 -0
  116. package/dist/utils/validation.d.ts +146 -0
  117. package/dist/utils/validation.d.ts.map +1 -0
  118. package/package.json +156 -0
package/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # 📦 Plyaz Package Template
2
+
3
+ This is the official Plyaz internal **package template** — used to create and maintain shared libraries across all apps and services. It provides a consistent setup for TypeScript packages, full integration with `@plyaz/devtools`.
4
+
5
+ Use this when creating packages like:
6
+
7
+ - `@plyaz/types`
8
+ - `@plyaz/api`
9
+ - `@plyaz/errors`
10
+ - `@plyaz/web3`
11
+ - `@plyaz/config`
12
+
13
+ ---
14
+
15
+ ## 🚀 Getting Started
16
+
17
+ ### 🌀 Option 1: Use GitHub Template
18
+
19
+ 1. Go to [@plyaz/package-template](https://github.com/Plyaz-Official/package-template).
20
+ 2. Click **"Use this template"**.
21
+ 3. Name your new repo (e.g. `@plyaz/errors`, `@plyaz/types`).
22
+ 4. Clone the repo:
23
+ ```bash
24
+ git clone https://github.com/Plyaz-Official/package-template.git @plyaz/types
25
+ cd @plyaz/types
26
+ pnpm install
27
+ ````
28
+
29
+ ### 🗂 Option 2: Manual Clone
30
+
31
+ ```bash
32
+ git clone https://github.com/Plyaz-Official/package-template.git @plyaz/my-package
33
+ cd @plyaz/my-package
34
+ pnpm install
35
+ ```
36
+
37
+ Then update:
38
+
39
+ * `package.json > name` → `@plyaz/my-package`
40
+ * `package.json > disable-publish` → Remove it
41
+ * `README.md`, GitHub metadata, CI/CD labels
42
+
43
+ ---
44
+
45
+ ## 📦 Project Structure
46
+
47
+ ```
48
+ ├── src/
49
+ │ └── index.ts # Main entry point (exports)
50
+ ├──── test/
51
+ │ └── index.test.ts # Unit tests using Vitest
52
+ ├── package.json # Package metadata
53
+ ├── tsconfig.json # Uses @plyaz/devtools base
54
+ ├── eslint.config.mjs # Uses @plyaz/devtools eslint rules
55
+ ├── .prettier.mjs # Uses @plyaz/devtools formatting rules
56
+ ├── .vitest.config.mjs # Uses @plyaz/devtools vitest config
57
+ ├── .vitest.setup.mjs # Uses @plyaz/devtools vitest setup
58
+ ```
59
+
60
+ ---
61
+
62
+ ## 📜 Scripts & Commands
63
+
64
+ ```json
65
+ {
66
+ "build": "tsc --build",
67
+ "test": "vitest run",
68
+ "lint": "eslint .",
69
+ "lint:fix": "eslint . --fix",
70
+ "format": "prettier --write './**/*.{ts,js,json}'",
71
+ "format:check": "prettier --check './**/*.{ts,js,json}'",
72
+ "type:check": "tsc --noEmit"
73
+ }
74
+ ```
75
+
76
+ ---
77
+
78
+ ## 🔁 Dev Workflow
79
+
80
+ ### Local Linking (for active development)
81
+
82
+ In the **package repo**:
83
+
84
+ ```bash
85
+ pnpm build
86
+ pnpm link --global
87
+ ```
88
+
89
+ In a **consumer repo** (e.g. frontend app):
90
+
91
+ ```bash
92
+ pnpm link --global @plyaz/my-package
93
+ ```
94
+
95
+ ### Publishing to GitHub Packages
96
+
97
+ Ensure `.npmrc` in your user root exists:
98
+
99
+ ```npmrc
100
+ @plyaz:registry=https://npm.pkg.github.com/
101
+ //npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
102
+ ```
103
+
104
+ Then publish:
105
+
106
+ ```bash
107
+ pnpm publish --access=restricted
108
+ ```
109
+
110
+ ---
111
+
112
+ ## ✅ Best Practices
113
+
114
+ * Always export from `src/index.ts`
115
+ * Use semver (`1.2.0`) and follow changelog conventions
116
+ * Keep isolated logic: packages should not import from app-specific code
117
+ * Use `@plyaz/devtools` for all configs: ESLint, Prettier, TS, Vitest, CI and other configs
118
+ * Include unit tests via `vitest`
119
+ * Enable CI/CD via GitHub Actions template (see `.github/workflows/publish.yml`, `.github/workflows/security.yml`, `.github/workflows/deploy.yml`)
120
+
121
+ ---
122
+
123
+ ## 🧰 Shared Tooling
124
+
125
+ This template is pre-integrated with:
126
+
127
+ * ✅ TypeScript (strict mode)
128
+ * ✅ ESLint & Prettier via `@plyaz/devtools`
129
+ * ✅ Unit testing (Vitest)
130
+ * ✅ CI-ready for GitHub Actions
131
+ * ✅ `.npmrc` for GitHub Package Registry
132
+
133
+ For full integration, ensure you're using the latest `@plyaz/devtools` and follow the [Plyaz Confluence Documentation](https://plyaz.atlassian.net/wiki/spaces/SD/overview).
134
+
135
+ ---
136
+
137
+ ## 🔐 GitHub Secrets (Required)
138
+
139
+ To enable private publishing via CI/CD, set the following in your GitHub repo secrets:
140
+
141
+ ```env
142
+ GITHUB_TOKEN=<automatically available>
143
+ ```
144
+
145
+ ---
146
+
147
+ ## 📄 When to Use a Shared Package
148
+
149
+ Use this template if your logic or types:
150
+
151
+ * Are used by 2+ apps/services
152
+ * Need semantic versioning and reuse
153
+ * Should remain independently tested and documented
154
+
155
+ For example:
156
+
157
+ | Package | Description |
158
+ | --------------- | ------------------------------------------- |
159
+ | `@plyaz/types` | Global TypeScript types and interfaces |
160
+ | `@plyaz/api` | Shared API SDK and HTTP clients |
161
+ | `@plyaz/errors` | Standardized error shapes and handlers |
162
+ | `@plyaz/web3` | Web3 interaction layer (wallets, contracts) |
163
+ | `@plyaz/config` | Shared config/env/constants (no logic) |
164
+
165
+ ---
166
+
167
+ ## 🧠 Ownership
168
+
169
+ This repo is managed by the Plyaz engineering team. Please follow versioning, changelog, and testing requirements when contributing.
@@ -0,0 +1,269 @@
1
+ import type { DrizzleAdapterConfig, DatabaseAdapterType, DatabaseResult, PaginatedResult, QueryOptions, DatabaseHealthStatus, Filter, Transaction } from "@plyaz/types/db";
2
+ /**
3
+ * @class DrizzleAdapter
4
+ * @implements {DatabaseAdapterType}
5
+ * @classdesc
6
+ * A PostgreSQL database adapter built on top of Drizzle ORM.
7
+ * Provides generic CRUD operations, pagination, filtering, sorting,
8
+ * and transactional support with a consistent result structure.
9
+ */
10
+ export declare class DrizzleAdapter implements DatabaseAdapterType {
11
+ private db;
12
+ private pool;
13
+ private config;
14
+ private tableMap;
15
+ private idColumnMap;
16
+ /**
17
+ * Creates a new DrizzleAdapter instance.
18
+ * @param {DrizzleAdapterConfig} config - Configuration object for Drizzle and PostgreSQL connection.
19
+ * @description
20
+ * Initializes the adapter with the provided configuration, setting up the connection pool
21
+ * and creating a Drizzle ORM instance. The configuration should include a connection string
22
+ * and optional pool settings such as min/max connections and idle timeout.
23
+ */
24
+ constructor(config: DrizzleAdapterConfig);
25
+ /**
26
+ * Initializes the adapter by verifying database connectivity.
27
+ * @returns {Promise<DatabaseResult<void>>} Success or failure result.
28
+ * @description
29
+ * Attempts to establish a connection to the database to verify that the adapter
30
+ * can communicate with the database. This is typically called during application startup
31
+ * to ensure the database is accessible before performing any operations.
32
+ * Returns a success result if the connection is established, or a failure result with an error
33
+ * if the connection cannot be established.
34
+ */
35
+ initialize(): Promise<DatabaseResult<void>>;
36
+ /**
37
+ * Opens a new connection to the database.
38
+ * @returns {Promise<void>}
39
+ * @description
40
+ * Establishes a connection to the PostgreSQL database using the connection pool.
41
+ * This method is called to ensure that a connection is available before performing database operations.
42
+ * The connection pool manages the connections efficiently, reusing them when possible.
43
+ */
44
+ connect(): Promise<void>;
45
+ /**
46
+ * Closes all open connections and shuts down the connection pool.
47
+ * @returns {Promise<void>}
48
+ * @description
49
+ * Gracefully shuts down the connection pool, closing all active connections.
50
+ * This method should be called when the adapter is no longer needed, typically during
51
+ * application shutdown, to free up database resources and prevent connection leaks.
52
+ */
53
+ disconnect(): Promise<void>;
54
+ /**
55
+ * Gets the underlying Drizzle client instance.
56
+ * @returns {TClient} The internal Drizzle client.
57
+ * @description
58
+ * This method exposes the internal Drizzle client instance. Direct access is discouraged
59
+ * to maintain abstraction and ensure all database operations go through the adapter’s
60
+ * interface for error handling, logging, and event emission.
61
+ */
62
+ getClient<TClient extends object = object>(): TClient;
63
+ /**
64
+ * Executes a raw SQL query.
65
+ * @template T - The expected type of the query result rows.
66
+ * @param {string} sql - Raw SQL query string.
67
+ * @param {T[]} [params] - Optional query parameters.
68
+ * @returns {Promise<T[]>} Array of query result rows.
69
+ * @throws {DatabaseError} When query execution fails.
70
+ * @description
71
+ * Executes a raw SQL query against the database, with optional parameterization.
72
+ * This method is useful for complex queries that cannot be easily expressed using the ORM
73
+ * or for database-specific operations. The method uses parameterized queries to prevent
74
+ * SQL injection attacks. If the query execution fails, a DatabaseError is thrown.
75
+ */
76
+ query<T>(sql: string, params?: T[]): Promise<T[]>;
77
+ /**
78
+ * Registers a table and optional ID column for ORM operations.
79
+ * @template TTable - Type representing the table structure.
80
+ * @template TIdColumn - Type representing the ID column.
81
+ * @param {string} name - Logical name of the table.
82
+ * @param {TTable} table - Drizzle table object.
83
+ * @param {TIdColumn} [idColumn] - Optional primary key column.
84
+ * @description
85
+ * Registers a table with the adapter, allowing it to be referenced by a logical name
86
+ * in subsequent operations. This is necessary for the adapter to perform ORM operations
87
+ * on the table. The ID column can also be specified if it differs from the default 'id'.
88
+ * This registration enables the adapter to map logical table names to actual table objects
89
+ * and ID columns, providing a layer of abstraction between the application and the database schema.
90
+ */
91
+ registerTable<TTable, TIdColumn>(name: string, table: TTable, idColumn?: TIdColumn): void;
92
+ /**
93
+ * Finds a record by its primary ID.
94
+ * @template T - The expected type of the record.
95
+ * @param {string} table - Table name.
96
+ * @param {string} id - Record ID.
97
+ * @returns {Promise<DatabaseResult<T | null>>} Found record or null.
98
+ * @description
99
+ * Retrieves a single record from the specified table using its primary ID.
100
+ * The method uses the registered table and ID column to construct the query.
101
+ * If the record is found, it is returned in a success result. If no record is found,
102
+ * null is returned in a success result. If an error occurs during the operation,
103
+ * a failure result with an error message is returned.
104
+ */
105
+ findById<T>(table: string, id: string): Promise<DatabaseResult<T | null>>;
106
+ /**
107
+ * Retrieves multiple records with optional filtering, sorting, and pagination.
108
+ * @template T - The expected type of the records.
109
+ * @param {string} table - Table name.
110
+ * @param {QueryOptions} [options] - Optional filter, sort, and pagination options.
111
+ * @returns {Promise<DatabaseResult<PaginatedResult<T>>>} Paginated result set.
112
+ * @description
113
+ * Retrieves multiple records from the specified table with support for filtering,
114
+ * sorting, and pagination. The method first applies any filters to narrow down the result set,
115
+ * then applies sorting to order the results, and finally applies pagination to limit the number
116
+ * of records returned. The result includes the data array, total count of matching records,
117
+ * and pagination metadata such as current page, total pages, and next/previous cursors.
118
+ * If an error occurs during the operation, a failure result with an error message is returned.
119
+ */
120
+ findMany<T>(table: string, options?: QueryOptions): Promise<DatabaseResult<PaginatedResult<T>>>;
121
+ /**
122
+ * Inserts a new record into the specified table.
123
+ * @template T - The expected type of the record.
124
+ * @param {string} table - Table name.
125
+ * @param {T} data - Record to insert.
126
+ * @returns {Promise<DatabaseResult<T>>} Inserted record.
127
+ * @description
128
+ * Inserts a new record into the specified table using the provided data.
129
+ * The method uses the registered table to construct the insert query.
130
+ * After insertion, it returns the inserted record with any auto-generated fields
131
+ * (like IDs) populated. If an error occurs during the operation,
132
+ * a failure result with an error message is returned.
133
+ */
134
+ create<T>(table: string, data: T): Promise<DatabaseResult<T>>;
135
+ /**
136
+ * Updates an existing record by ID.
137
+ * @template T - The expected type of the record.
138
+ * @param {string} table - Table name.
139
+ * @param {string} id - Record ID.
140
+ * @param {Partial<T>} data - Partial object containing fields to update.
141
+ * @returns {Promise<DatabaseResult<T>>} Updated record.
142
+ * @description
143
+ * Updates an existing record in the specified table using its primary ID.
144
+ * Only the fields provided in the data object are updated, allowing for partial updates.
145
+ * The method uses the registered table and ID column to construct the update query.
146
+ * After updating, it returns the updated record. If an error occurs during the operation,
147
+ * a failure result with an error message is returned.
148
+ */
149
+ update<T>(table: string, id: string, data: Partial<T>): Promise<DatabaseResult<T>>;
150
+ /**
151
+ * Deletes a record by ID.
152
+ * @param {string} table - Table name.
153
+ * @param {string} id - Record ID.
154
+ * @returns {Promise<DatabaseResult<void>>}
155
+ * @description
156
+ * Deletes a record from the specified table using its primary ID.
157
+ * The method uses the registered table and ID column to construct the delete query.
158
+ * If the operation is successful, it returns a success result with no value.
159
+ * If an error occurs during the operation, a failure result with an error message is returned.
160
+ */
161
+ delete(table: string, id: string): Promise<DatabaseResult<void>>;
162
+ /**
163
+ * Executes a transactional operation with rollback on failure.
164
+ * @template T - The expected type of the transaction result.
165
+ * @param {(trx: Transaction) => Promise<T>} callback - Function executed within a transaction.
166
+ * @returns {Promise<DatabaseResult<T>>} Transaction result.
167
+ * @description
168
+ * Executes a callback function within a database transaction, providing atomicity.
169
+ * If the callback function executes successfully, the transaction is committed.
170
+ * If an error occurs during the execution of the callback function, the transaction
171
+ * is rolled back, ensuring that no partial changes are applied to the database.
172
+ * The method returns the result of the callback function if successful,
173
+ * or a failure result with an error message if an error occurs.
174
+ */
175
+ transaction<T>(callback: (trx: Transaction) => Promise<T>): Promise<DatabaseResult<T>>;
176
+ /**
177
+ * Checks if a record exists by ID.
178
+ * @param {string} table - Table name.
179
+ * @param {string} id - Record ID.
180
+ * @returns {Promise<DatabaseResult<boolean>>} True if exists, otherwise false.
181
+ * @description
182
+ * Checks if a record with the specified ID exists in the table.
183
+ * The method uses the registered table and ID column to construct the query.
184
+ * It returns a success result with a boolean value indicating whether the record exists.
185
+ * If an error occurs during the operation, a failure result with an error message is returned.
186
+ */
187
+ exists(table: string, id: string): Promise<DatabaseResult<boolean>>;
188
+ /**
189
+ * Counts records matching an optional filter.
190
+ * @param {string} table - Table name.
191
+ * @param {Filter} [filter] - Optional filter object.
192
+ * @returns {Promise<DatabaseResult<number>>} Total count of matching records.
193
+ * @description
194
+ * Counts the number of records in the specified table that match the optional filter.
195
+ * The method uses the registered table to construct the count query.
196
+ * If a filter is provided, it is applied to narrow down the count to matching records.
197
+ * It returns a success result with the count of matching records.
198
+ * If an error occurs during the operation, a failure result with an error message is returned.
199
+ */
200
+ count(table: string, filter?: Filter): Promise<DatabaseResult<number>>;
201
+ /**
202
+ * Performs a health check on the database connection.
203
+ * @returns {Promise<DatabaseResult<DatabaseHealthStatus>>} Health status with response time.
204
+ * @description
205
+ * Checks the health of the database connection by executing a simple query.
206
+ * The method measures the response time of the query to determine the health status.
207
+ * It returns a success result with a HealthStatus object indicating whether the database is healthy,
208
+ * the response time of the health check, and any additional details.
209
+ * If an error occurs during the operation, a failure result with an error message is returned.
210
+ */
211
+ healthCheck(): Promise<DatabaseResult<DatabaseHealthStatus>>;
212
+ /**
213
+ * Retrieves a registered table by name.
214
+ * @private
215
+ * @param {string} name - Table name.
216
+ * @returns {PgTable} Table object.
217
+ * @throws {DatabaseError} If table is not registered.
218
+ * @description
219
+ * Retrieves a table object that has been previously registered with the adapter.
220
+ * This method is used internally by other methods to ensure that operations are performed
221
+ * on valid, registered tables. If the table is not found, it throws a DatabaseError.
222
+ */
223
+ private getTable;
224
+ /**
225
+ * Retrieves the registered ID column for a table.
226
+ * @private
227
+ * @param {string} name - Table name.
228
+ * @returns {PgColumn} ID column.
229
+ * @throws {DatabaseError} If ID column is not registered.
230
+ * @description
231
+ * Retrieves the ID column that has been previously registered for a table.
232
+ * This method is used internally by other methods to ensure that operations that require
233
+ * the ID column can access it. If the ID column is not found, it throws a DatabaseError.
234
+ */
235
+ private getIdColumn;
236
+ /**
237
+ * Builds a SQL `WHERE` clause based on filter operators.
238
+ * @private
239
+ * @param {Filter} filter - Filter definition.
240
+ * @param {PgTable} table - Table to apply filter on.
241
+ * @returns {SQL | undefined} SQL condition object.
242
+ * @throws {DatabaseError} If column or operator is invalid.
243
+ * @description
244
+ * Builds a SQL WHERE clause based on the provided filter definition.
245
+ * It supports various operators like equality, comparison, and null checks.
246
+ * If the column specified in the filter does not exist in the table, or if the operator
247
+ * is not supported, it throws a DatabaseError. The method returns an SQL object that
248
+ * can be used in queries, or undefined if no valid clause can be constructed.
249
+ */
250
+ private buildWhereClause;
251
+ /**
252
+ * Applies sorting to a query using provided field and direction.
253
+ * @private
254
+ * @template TQuery - Type of the query builder.
255
+ * @template TTable - Type of the table.
256
+ * @param {TQuery} query - Drizzle query builder.
257
+ * @param {SortOptions[]} sort - Array of sort conditions.
258
+ * @param {TTable} table - Target table.
259
+ * @returns {TQuery} Modified query with applied sorting.
260
+ * @throws {DatabaseError} If field is invalid or missing.
261
+ * @description
262
+ * Applies sorting to a Drizzle query based on the provided sort options.
263
+ * It supports sorting by multiple fields in ascending or descending order.
264
+ * If a field specified in the sort options does not exist in the table, or is not a valid column,
265
+ * it throws a DatabaseError. The method returns the modified query with the sorting applied.
266
+ */
267
+ private applySorting;
268
+ }
269
+ //# sourceMappingURL=DrizzleAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DrizzleAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/drizzle/DrizzleAdapter.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Database adapter implementations
3
+ * @module adapters
4
+ */
5
+ /**
6
+ * Drizzle ORM adapter for PostgreSQL databases
7
+ * @exports DrizzleAdapter
8
+ */
9
+ export { DrizzleAdapter } from "./drizzle/DrizzleAdapter";
10
+ /**
11
+ * Supabase adapter for PostgreSQL databases
12
+ * @exports SupabaseAdapter
13
+ */
14
+ export { SupabaseAdapter } from "./supabase/SupabaseAdapter";
15
+ /**
16
+ * Plain SQL adapter for PostgreSQL databases
17
+ * @exports SQLAdapter
18
+ */
19
+ export { SQLAdapter } from "./sql/SQLAdapter";
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D;;;GAGG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}