Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support savePoint #55

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ts支持savepoint
  • Loading branch information
liangfujian committed Sep 8, 2023
commit 351944fb7e2beff88e3730000688704b368a4108
11 changes: 11 additions & 0 deletions generator/client/typescript/templates/queryx/adapter.mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ export class Adapter {
async rollback() {
await this.db.query("ROLLBACK");
}

async savePoint(sp: string){
await this.exec(`SAVEPOINT ${sp}`);
}
async releasePoint(rp: string){
await this.exec(`RELEASE SAVEPOINT ${rp}`);
}

async rollbackTo(rt: string){
await this.exec(`ROLLBACK TO ${rt}`);
}
}

export function rebind<T extends any[] = any[]>(query: string, args?: T) {}
Expand Down
12 changes: 12 additions & 0 deletions generator/client/typescript/templates/queryx/adapter.postgresql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ export class Adapter {
async rollback() {
await this.exec("ROLLBACK");
}

async savePoint(sp: string){
await this.exec(`SAVEPOINT ${sp}`);
}
async releasePoint(rp: string){
await this.exec(`RELEASE SAVEPOINT ${rp}`);
}

async rollbackTo(rt: string){
await this.exec(`ROLLBACK TO ${rt}`);
}

}

export function rebind<T extends any[] = any[]>(query: string, args?: T) {
Expand Down
11 changes: 11 additions & 0 deletions generator/client/typescript/templates/queryx/adapter.sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ export class Adapter {
async rollback() {
await this.exec("ROLLBACK");
}

async savePoint(sp: string){
await this.exec(`SAVEPOINT ${sp}`);
}
async releasePoint(rp: string){
await this.exec(`RELEASE SAVEPOINT ${rp}`);
}

async rollbackTo(rt: string){
await this.exec(`ROLLBACK TO ${rt}`);
}
}

export function rebind<T extends any[] = any[]>(query: string, args?: T) {
Expand Down
12 changes: 12 additions & 0 deletions generator/client/typescript/templates/queryx/client.tstmpl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ export class Tx extends QXClient {
rollback() {
return this.adapter.rollback();
}

savePoint(sp: string){
return this.adapter.savePoint(sp)
}

releasePoint(rp: string){
return this.adapter.releasePoint(rp)
}

rollbackTo(rt: string){
return this.adapter.rollbackTo(rt)
}
}

export const newClient = () => {
Expand Down
18 changes: 18 additions & 0 deletions internal/integration/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,24 @@ test("transaction", async () => {
expect(tag1.name).toEqual("tag1-updated");
});


test("savepoint", async () => {
let tx = await c.tx();
let tagPoint = "sp_point"

await tx.queryTag().create({name:"tagPoint1"})
await tx.savePoint(tagPoint)

await tx.queryTag().create({name: "tagPoint2"})
await tx.rollbackTo(tagPoint)

await tx.queryTag().where(tx.tagName.eq("tagPoint1")).exists()
await tx.queryTag().where(tx.tagName.eq("tagPoint2")).exists()

await tx.releasePoint(tagPoint)
await tx.commit()
});

test("changeJSON", async () => {
let userChange = new UserChange({
name: "user name",
Expand Down
Loading