Reputation: 177
I am trying to update a record in mnesia with mnesia:write() but how do I make sure that this function will insert if record doesn't exist
Record Looks like this: (Id, Node, Timestamp, Level, Msg)
Please Help
Upvotes: 0
Views: 527
Reputation: 48649
I am trying to update a record in mnesia with mnesia:write() but how do I make sure that this function will insert if record doesn't exist
You don't have to try very hard because that is what mnesia:write(Table, Record, LockKind) does:
Writes record Record to table Tab.
Note that the description doesn't say:
Record is written to Tab only if Record already exists in Tab.
which would be at odds with any database I've ever used, and would make me wonder how you would be able to write anything to a table. You would start with an empty table, and if write/3
didn't let you write a record to a table unless the record was already in the table, then you would never be able to add a record to an empty table.
For all the mnesia table types (set, ordered set, and bag), write/3
will write a Record to the table.
Upvotes: 2