This repository was archived by the owner on Sep 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
This repository was archived by the owner on Sep 9, 2021. It is now read-only.
Generalizing data store interface #39
Copy link
Copy link
Closed
Labels
need/triageNeeds initial labeling and prioritizationNeeds initial labeling and prioritization
Description
In an attempt to untangle generalized datastore interface discussion from query
interface in #9, I'm forking former here.
I was trying to make an argument in favor of generalized DataStore
interface that concrete data stores could be specialized implementations of. More concretely I was proposing following:
export interface Store<K, V, E> {
has(key:K, options?:StoreOptions):Promise<boolean>
put(key:K, value:V, options?:StoreOptions):Promise<void>
putMany(source:Many<E>, options?:StoreOptions):AsyncIterable<E>
get(key:K, options?:StoreOptions):Promise<V>
getMany(source:Many<K>, options?:StoreOptions):AsyncIterable<V>
delete(key:K, options?:StoreOptions):Promise<void>
deleteMany(source:Many<K>, options?:StoreOptions):AsyncIterable<K>
query(query:Query<E>, options?:StoreOptions):AsyncIterable<E>
batch():StoreBatch<K, V>
open():Promise<void>
close():Promise<void>
}
type Many<T> =
| Iterable<T>
| AsyncIterable<T>
type StoreOptions = {
timeout?:number
signal?: AbortSignal
}
interface Query<E> {
prefix?:string,
filters?:Array<(input:E => boolean>,
orders?:Array<(input:E[]) => E[]>,
limit?:number,
offset?:number,
timeout?:number,
signal?:AbortSignal
}
interface StoreBatch<K, V> {
put(key:K, value:V, options?:StoreOptions):void,
delete(key:K, options?:StoreOptions):void,
commit():Promise<void>
}
This would allow individual stores in the system to be concrete implementations of generic interface:
import CID from "cids"
import Block from 'ipld-block'
class BlockStore implements Store <CID, Block, Block> {
// ...
}
Note: That Block
already encapsulates key and value so value and entry end up being same type.
class DataStore implements Store<Key, Buffer, [Key, Buffer]> {
// ...
}
Note some alterations had being made to query
API but they are not essential to this, just make more sense IMO.
Metadata
Metadata
Assignees
Labels
need/triageNeeds initial labeling and prioritizationNeeds initial labeling and prioritization