> For the complete documentation index, see [llms.txt](https://dexiejs.typogram.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dexiejs.typogram.co/dexie/dexie.transaction-old-version.md).

# Dexie.transaction()-(old-version)

*Since version 0.9.8 a new transaction style was introduced. The API is still backward compatible with the documentation on this page but it is encourage to migrate your code according to the new version of Dexie.transaction()*

#### Syntax

```javascript
db.transaction(mode, table, [table2], [tableN], ..., callback)
```

#### Parameters

| mode : String       | "r" = readonly or "rw" = readwrite                                    |
| ------------------- | --------------------------------------------------------------------- |
| table : Table       | Object store to include in transaction. Pick it from db.\[tablename]. |
| table2 : Table      | -- " --                                                               |
| tableN, ... : Table | -- " --                                                               |
| callback : Function | function (table, table2, tableN, ..., transaction) {...}              |

#### Callback Parameters

| table : Table or [WriteableTable](https://github.com/dexie/Dexie.js/wiki/WriteableTable) | <p>Transaction-based Table to work on.<br>If mode == "r", instance will be Table<br>If mode == "rw", instance will be <a href="https://github.com/dexie/Dexie.js/wiki/WriteableTable">WriteableTable</a></p> |
| ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| table2                                                                                   | -- " --                                                                                                                                                                                                      |
| tableN, ...                                                                              | -- " --                                                                                                                                                                                                      |
| transaction : Transaction                                                                |                                                                                                                                                                                                              |

#### Return Value

Promise

#### Sample

```javascript
var db = new Dexie("FriendsAndPetsDatabase");
db.version(1).stores({
    friends: "++id,name,isCloseFriend",
    pets: "++id,name,kind"
});
db.open(); 
db.transaction("rw", db.friends, db.pets, function(friends, pets, transaction) {
    // Since mode is "rw", we can add objects to the object stores
    friends.add({name: "Måns", isCloseFriend: 1});
    friends.add({name: "Nils", isCloseFriend: 1});
    friends.add({name: "Jon", isCloseFriend: 1});
    pets.add({name: "Josephina", kind: "dog"});

    // In case you need to access the transaction object, here's an example of that:
    transaction.on("abort", function() {
        console.log("Transaction aborted");
    });

    // Since we are in a transaction, we can query the table right away.
    // If this was not in a transaction, we would have to wait for
    // all three add() operations
    // to complete before querying it if we would like to get the latest added data.
    friends.where("isCloseFriend").equals(1).each(function(friend){
        console.log("Found close friend: " + friend.name);
        // Any database error event that occur will abort transaction and
        // be sent to the catch() method below.
        // The exact same rule if any exception is thrown what so ever.
    });
}).catch(function (error) {
    // Log or display the error
    console.error(error.stack || error);
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dexiejs.typogram.co/dexie/dexie.transaction-old-version.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
