Safe Haskell | Safe-Infered |
---|
Snap-agnostic low-level CRUD operations. No model definitions are used on this level. Instead, objects must be
This module may be used for batch uploading of database data.
- create :: ModelName -> Commit -> [FieldIndex] -> Redis (Either Reply InstanceId)
- update :: ModelName -> InstanceId -> Commit -> [FieldIndex] -> Redis (Either Reply ())
- delete :: ModelName -> InstanceId -> [FieldIndex] -> Redis (Either Reply ())
- type InstanceId = ByteString
- instanceKey :: ModelName -> InstanceId -> ByteString
- modelIndex :: ModelName -> ByteString -> ByteString -> ByteString
- modelTimeline :: ModelName -> ByteString
- collate :: FieldValue -> FieldValue
- onlyFields :: Commit -> [FieldName] -> [Maybe FieldValue]
CRUD operations
:: ModelName | Model name |
-> Commit | Key-values of instance data |
-> [FieldIndex] | |
-> Redis (Either Reply InstanceId) |
Create new instance in Redis and indices for it.
Bump model id counter and update timeline, return new instance id.
TODO: Support pubsub from here
update :: ModelName -> InstanceId -> Commit -> [FieldIndex] -> Redis (Either Reply ())Source
Modify existing instance in Redis, updating indices
TODO: Handle non-existing instance as error here?
delete :: ModelName -> InstanceId -> [FieldIndex] -> Redis (Either Reply ())Source
Remove existing instance in Redis, cleaning up old indices.
Does not check if instance exists.
Redis helpers
type InstanceId = ByteStringSource
instanceKey :: ModelName -> InstanceId -> ByteStringSource
Build Redis key given model name and instance id
:: ModelName | |
-> ByteString | Field name |
-> ByteString | Field value |
-> ByteString |
Build Redis key for field index of model.
modelTimeline :: ModelName -> ByteStringSource
Get Redis key which stores timeline for model
collate :: FieldValue -> FieldValueSource
Strip value of punctuation, spaces, convert all to lowercase.
onlyFields :: Commit -> [FieldName] -> [Maybe FieldValue]Source
Extract values of named fields from commit.