autoincrement
This is the equivalent of Prisma's autoincrement(). It automatically assigns unique, monotonically increasing values during create operations.
Basic Usage
const gassma = new Gassma.GassmaClient({
autoincrement: {
Users: "id",
},
});
// id is automatically assigned during create
gassma.Users.create({
data: { name: "Alice" },
});
// => \{ id: 1, name: "Alice" \}
gassma.Users.create({
data: { name: "Bob" },
});
// => \{ id: 2, name: "Bob" \}
Multiple Columns
You can specify multiple columns using an array.
autoincrement: {
Users: ["id", "seq"],
}
Behavior with createMany
With createMany, counters for all rows are reserved at once before being assigned to each row.
gassma.Users.createMany({
data: [{ name: "Alice" }, { name: "Bob" }],
});
// => id: 1, 2 are assigned respectively
How It Works
- Exclusive control via
LockService.getScriptLock().waitLock(10000) - Read the counter from
PropertiesService.getScriptProperties() - Increment by +1 (+N for createMany) and write back
- Release the lock
note
This feature only works in the GAS environment because it uses GAS's LockService and PropertiesService.
Behavior with Explicit Values
If a value is explicitly specified for a field, auto-increment is skipped.
gassma.Users.create({
data: { id: 100, name: "Alice" },
});
// => id is 100 (auto-increment is not applied)