Sequence API
Aidbox provides access to PostgreSQL sequences through REST API.
Last updated
Was this helpful?
Aidbox provides access to PostgreSQL sequences through REST API.
Last updated
Was this helpful?
In some cases you want to enumerate your resources with an increasing counter or use global sequences for your app needs. Aidbox provides handy access to through REST API. Values generated by this API are transactional and safe to use in concurrent environment.
You can create named sequence by posting PGSequence resource. We use explicit naming for sequences, so the id element is required!
You can specify other PGSequence attributes:
id
ident
sequence name; only lower case, digits and _ are allowed in name
start
integer
initial sequence value (default 1)
cycle
boolean
cycle after reaching sequence max/min value
increment
integer
sequence step (default 1)
maxval
integer
max value to cycle
minval
integer
min value to cycle
Now you can move sequence forward transactionally and reserve the next value:
Each call will increment the sequence.
You can get a range of values by providing the count parameter in the body.
You can read the current state of sequence without incrementing it with GET /PGSequence/[id]
You can set the sequence to a specific value by PUT /PGSequence/[id]
This will reset the current sequence value to 30, so next get value operation will return 31:
You can use this endpoint if you want to update or create sequence:
You can drop the sequence with DELETE /PGSequence/[id]