Skip to content

Commit

Permalink
Merge pull request #11 from koyopro/feature/readme
Browse files Browse the repository at this point in the history
update README for Transactions
  • Loading branch information
koyopro authored Jun 9, 2024
2 parents d52bda6 + 51c12ad commit 2dff62f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
24 changes: 23 additions & 1 deletion packages/accel-record/README-ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,29 @@ User.import(users, {
});
```
## トランザクション
`Model.transaction()` メソッドでトランザクションを利用できます。`Rollback` を例外として投げることでトランザクションをロールバックすることができ、トランザクションはネストすることができます。
```ts
import { User } from "./models/index.js";

User.transaction(() => {
User.create({});
console.log(User.count()); // => 1

User.transaction(() => {
User.create({});
console.log(User.count()); // => 2

// Rollback の throw により内側のトランザクションはロールバックされます
throw new Rollback();
});
// 外側のトランザクションはコミットされます
});
console.log(User.count()); // => 1
```
## Nullableな値の扱いについて
Nullableな値について、TypeScriptではJavaScriptと同様にundefinedとnullの2つが存在します。 \
Expand Down Expand Up @@ -1001,7 +1024,6 @@ user.update({ age: undefined });
## 今後予定されている機能追加
- [accel-record-core] スコープ
- [accel-record-core] トランザクションのネスト
- [accel-record-core] PostgreSQLのサポート
- [accel-record-core] 複合IDの対応
- [accel-record-core] クエリインターフェースの拡充
Expand Down
24 changes: 23 additions & 1 deletion packages/accel-record/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,29 @@ User.import(users, {
});
```
## Transactions
You can use the `Model.transaction()` method to utilize transactions. By throwing a `Rollback` exception, you can rollback the transaction, and transactions can be nested.
```ts
import { User } from "./models/index.js";

User.transaction(() => {
User.create({});
console.log(User.count()); // => 1

User.transaction(() => {
User.create({});
console.log(User.count()); // => 2

// The inner transaction is rolled back by throwing a Rollback
throw new Rollback();
});
// The outer transaction is committed
});
console.log(User.count()); // => 1
```
## Nullable Values Handling
Regarding nullable values, TypeScript, like JavaScript, has two options: undefined and null. \
Expand Down Expand Up @@ -1000,7 +1023,6 @@ user.update({ age: undefined });
## Future Planned Features
- [accel-record-core] Scopes
- [accel-record-core] Nested Transactions
- [accel-record-core] PostgreSQL Support
- [accel-record-core] Support for Composite IDs
- [accel-record-core] Expansion of Query Interface
Expand Down

0 comments on commit 2dff62f

Please sign in to comment.