dream_ets/helpers
Convenience helpers for common ETS use cases
All convenience functions that create tables MUST use the builder internally.
Values
pub fn decrement(
table: table.Table(String, Int),
key: String,
) -> Result(Int, table.EtsError)
Atomically decrement a counter value
If the key doesn’t exist, it’s created with value -1. Returns the new value after decrementing.
pub fn decrement_by(
table: table.Table(String, Int),
key: String,
amount: Int,
) -> Result(Int, table.EtsError)
Atomically decrement a counter value by a specific amount
If the key doesn’t exist, it’s created with the negative of the specified amount. Returns the new value after decrementing.
pub fn increment(
table: table.Table(String, Int),
key: String,
) -> Result(Int, table.EtsError)
Atomically increment a counter value
If the key doesn’t exist, it’s created with value 1. Returns the new value after incrementing.
pub fn increment_by(
table: table.Table(String, Int),
key: String,
amount: Int,
) -> Result(Int, table.EtsError)
Atomically increment a counter value by a specific amount
If the key doesn’t exist, it’s created with the specified amount. Returns the new value after incrementing.
pub fn new_counter(
name: String,
) -> Result(table.Table(String, Int), table.EtsError)
Create a counter table (String keys, Int values)
This convenience function uses the builder pattern internally.
Equivalent to: ets.new(name) |> ets.counter() |> ets.create()
pub fn new_string_table(
name: String,
) -> Result(table.Table(String, String), table.EtsError)
Create a string-to-string table
This convenience function uses the builder pattern internally.