feat: Simplify OurDB.set function

- Remove unnecessary nested `if` statement in `OurDB.set`.
- Improve code readability and maintainability.
This commit is contained in:
Mahmoud Emad
2025-02-19 01:18:23 +02:00
parent 383fc9fade
commit f47703f599

View File

@@ -29,16 +29,14 @@ pub fn (mut db OurDB) set(args OurDBSetArgs) !u32 {
// if id points to an empty location, return an error
// else, overwrite data
if id := args.id {
if id != 0 {
// this is an update
location := db.lookup.get(id)!
if location.position == 0 {
return error('cannot set id for insertions when incremental mode is enabled')
}
db.set_(id, location, args.data)!
return id
// this is an update
location := db.lookup.get(id)!
if location.position == 0 {
return error('cannot set id for insertions when incremental mode is enabled')
}
db.set_(id, location, args.data)!
return id
}
// this is an insert