Skip to content

Commit 0f4e667

Browse files
committed
Release v0.6.0
1 parent a1871b9 commit 0f4e667

File tree

8 files changed

+52
-24
lines changed

8 files changed

+52
-24
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- uses: pnpm/action-setup@v2
2121
name: Install pnpm
2222
with:
23-
version: 8
23+
version: 9
2424
run_install: false
2525

2626
- name: Install dependencies

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
#### [v0.6.0](https://github.com/BemiHQ/bemi-prisma/compare/v0.5.0...v0.6.0) - 2024-10-14
4+
5+
- Fix compatibility with Prisma v5.20+
6+
37
#### [v0.5.0](https://github.com/BemiHQ/bemi-prisma/compare/v0.4.1...v0.5.0) - 2024-08-08
48

59
- Allow context passing only for specific models with `includeModels`

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ build:
66

77
publish:
88
npm publish --access public
9+
10+
test:
11+
pnpm run test

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,23 @@ psql -h [HOSTNAME] -U [USERNAME] -d [DATABASE] -c 'SELECT "primary_key", "table"
111111
27 | todo | DELETE | {"id": 27, "task": "Eat", "isCompleted": false} | {} | {"userId": 187234, "endpoint": "/todo/27", "params": {"id": 27}, "SQL": "DELETE FROM ..."} | 2023-12-11 17:09:18+00
112112
```
113113

114-
Check out our [Prisma Docs](https://docs.bemi.io/orms/prisma) for more details.
114+
Check out our [Prisma docs](https://docs.bemi.io/orms/prisma) for more details.
115115

116116
## Architecture overview
117117

118-
Bemi is designed to be lightweight and secure. It takes a practical approach to achieving the benefits of [event sourcing](https://martinfowler.com/eaaDev/EventSourcing.html) without requiring rearchitecting existing code, switching to highly specialized databases, or using unnecessary git-like abstractions on top of databases. We want your system to work the way it already does with your existing database to allow keeping things as simple as possible.
118+
Bemi is designed to be lightweight and secure. It takes a practical approach to achieving the benefits of [event sourcing](https://blog.bemi.io/rethinking-event-sourcing/) without requiring rearchitecting existing code, switching to highly specialized databases, or using unnecessary git-like abstractions on top of databases. We want your system to work the way it already does with your existing database to allow keeping things as simple as possible.
119119

120120
Bemi plugs into both the database and application levels, ensuring 100% reliability and a comprehensive understanding of every change.
121121

122-
On the database level, Bemi securely connects to PostgreSQL's [Write-Ahead Log](https://www.postgresql.org/docs/current/wal-intro.html) and implements [Change Data Capture](https://en.wikipedia.org/wiki/Change_data_capture). This allows tracking even the changes that get triggered via direct SQL.
122+
On the database level, Bemi securely connects to PostgreSQL's [Write-Ahead Log](https://www.postgresql.org/docs/current/wal-intro.html) and implements [Change Data Capture](https://blog.bemi.io/cdc/). This allows tracking even the changes that get triggered via direct SQL.
123123

124124
On the application level, this package automatically passes application context by using a [Prisma extension](https://www.prisma.io/docs/orm/prisma-client/client-extensions) to the replication logs to enhance the low-level database changes. For example, information about a user who made a change, an API endpoint where the change was triggered, a worker name that automatically triggered database changes, etc.
125125

126126
Bemi workers then stitch the low-level data with the application context and store this information in a structured easily queryable format, as depicted below:
127127

128128
![bemi-architechture](https://docs.bemi.io/img/architecture.png)
129129

130-
The cloud solution includes worker ingesters, queues for fault tolerance, and an automatically scalable cloud-hosted PostgreSQL. Bemi currently doesn't support a self hosted option, but [contact us](mailto:hi@bemi.io) if this is required.
130+
The cloud solution includes worker ingesters, queues for fault tolerance, and a serverless PostgreSQL. If you are interested in running a self-hosted version yourself, see our [self-hosting docs](https://docs.bemi.io/self-hosting).
131131

132132
## License
133133

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bemi-db/prisma",
3-
"version": "0.5.0",
3+
"version": "0.6.0",
44
"description": "Automatic data change tracking for Prisma",
55
"main": "dist/index.js",
66
"module": "./dist/index.mjs",
@@ -22,14 +22,14 @@
2222
},
2323
"homepage": "https://github.com/BemiHQ/bemi-prisma#readme",
2424
"dependencies": {
25-
"@prisma/driver-adapter-utils": "~5.15.0",
25+
"@prisma/driver-adapter-utils": "~5.20.0",
2626
"commander": "^11.1.0",
2727
"kleur": "^4.1.5",
2828
"pg": "^8.11.5",
2929
"postgres-array": "^3.0.2"
3030
},
3131
"peerDependencies": {
32-
"@prisma/client": "^5.15.0"
32+
"@prisma/client": "^5.20.0"
3333
},
3434
"devDependencies": {
3535
"@types/express": "^4.17.21",

src/conversion.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
// Last commit: https://github.com/prisma/prisma/commit/b36b73c2c349f80dc456dfd321f3c4cdc2aacfed#diff-848cf139de14ecb4c49c2e3f52703fecef4789f51052651f22ca2c5caf0afe99
1+
// Last commit: https://github.com/prisma/prisma/commit/47e8f1307ba73df65b80da32c4dd0d5e2816cc95
2+
// https://github.com/prisma/prisma/compare/b36b73c2c349f80dc456dfd321f3c4cdc2aacfed..47e8f1307ba73df65b80da32c4dd0d5e2816cc95
23

34
// @ts-ignore: this is used to avoid the `Module '"<path>/node_modules/@types/pg/index"' has no default export.` error.
5+
import { type ColumnType, ColumnTypeEnum } from '@prisma/driver-adapter-utils'
46
import pg from 'pg'
57
import { parse as parseArray } from 'postgres-array'
68

79
const { types } = pg
810
const { builtins: ScalarColumnType, getTypeParser } = types
9-
import { type ColumnType, ColumnTypeEnum } from '@prisma/driver-adapter-utils'
1011

1112
/**
1213
* PostgreSQL array column types (not defined in ScalarColumnType).
@@ -327,6 +328,13 @@ function normalize_money(money: string): string {
327328
return money.slice(1)
328329
}
329330

331+
/******************/
332+
/* XML handling */
333+
/******************/
334+
function normalize_xml(xml: string): string {
335+
return xml
336+
}
337+
330338
/*****************/
331339
/* JSON handling */
332340
/*****************/
@@ -410,6 +418,7 @@ export const customParsers = {
410418
[ArrayColumnType.BYTEA_ARRAY]: normalizeByteaArray,
411419
[ArrayColumnType.BIT_ARRAY]: normalize_array(normalizeBit),
412420
[ArrayColumnType.VARBIT_ARRAY]: normalize_array(normalizeBit),
421+
[ArrayColumnType.XML_ARRAY]: normalize_array(normalize_xml),
413422
}
414423

415424
// https://github.com/brianc/node-postgres/pull/2930

src/pg-adapter.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const callMockedPgAdapater = async (queries: string[]) => {
2222
const pgAdapter = new PrismaPg(client as any)
2323

2424
for(const sql of queries) {
25-
await pgAdapter['performIO']({ sql, args: [] })
25+
await pgAdapter['performIO']({ sql, args: [], argTypes: [] })
2626
}
2727

2828
return query

src/pg-adapter.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable @typescript-eslint/require-await */
2+
23
import type {
34
ColumnType,
45
ConnectionInfo,
@@ -8,6 +9,7 @@ import type {
89
Result,
910
ResultSet,
1011
Transaction,
12+
TransactionContext,
1113
TransactionOptions,
1214
} from '@prisma/driver-adapter-utils'
1315
import { Debug, err, ok } from '@prisma/driver-adapter-utils'
@@ -237,6 +239,23 @@ class PgTransaction extends PgQueryable<TransactionClient> implements Transactio
237239
}
238240
}
239241

242+
class PgTransactionContext extends PgQueryable<TransactionClient> implements TransactionContext {
243+
constructor(readonly conn: TransactionClient) {
244+
super(conn)
245+
}
246+
247+
async startTransaction(): Promise<Result<Transaction>> {
248+
const options: TransactionOptions = {
249+
usePhantomQuery: false,
250+
}
251+
252+
const tag = '[js::startTransaction]'
253+
debug('%s options: %O', tag, options)
254+
255+
return ok(new PgTransaction(this.conn, options))
256+
}
257+
}
258+
240259
export type PrismaPgOptions = {
241260
schema?: string
242261
}
@@ -276,21 +295,14 @@ const adapter = new PrismaPg(pool)
276295
})
277296
}
278297

279-
async startTransaction(): Promise<Result<Transaction>> {
280-
const options: TransactionOptions = {
281-
usePhantomQuery: false,
282-
}
283-
284-
const tag = '[js::startTransaction]'
285-
debug(`${tag} options: %O`, options)
286-
298+
async transactionContext(): Promise<Result<TransactionContext>> {
287299
// PATCH: Customize connection
288-
const connection = await this.client.connect() as TransactionClient
289-
connection.previousQueries = []
290-
connection.logQueries = this.logQueries
291-
connection.readyToExecuteTransaction = false
300+
const conn = await this.client.connect() as TransactionClient
301+
conn.previousQueries = []
302+
conn.logQueries = this.logQueries
303+
conn.readyToExecuteTransaction = false
292304
// PATCH: end
293305

294-
return ok(new PgTransaction(connection, options))
306+
return ok(new PgTransactionContext(conn))
295307
}
296308
}

0 commit comments

Comments
 (0)