Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Sharding and query #3

Merged
merged 13 commits into from
Nov 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.*/radium/.*
.*/standard-changelog/.*
.*/conventional-changelog-core/.*
.*/node_modules/.*

[include]

Expand Down
27 changes: 27 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "{build}"

environment:
matrix:
- nodejs_version: "6"

matrix:
fast_finish: true

install:
# Install Node.js
- ps: Install-Product node $env:nodejs_version

# Upgrade npm
- npm install -g npm

# Output our current versions for debugging
- node --version
- npm --version

# Install our package dependencies
- npm install

test_script:
- npm run test:node

build: off
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@
"David Dias <daviddias.p@gmail.com>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>"
]
}
}
48 changes: 20 additions & 28 deletions src/sharding.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

const waterfall = require('async/waterfall')
const parallel = require('async/parallel')
const pull = require('pull-stream')
const Key = require('interface-datastore').Key

const sh = require('./shard')
Expand Down Expand Up @@ -129,51 +128,44 @@ class ShardingDatastore {

query (q /* : Query<Buffer> */) /* : QueryResult<Buffer> */ {
const tq/* : Query<Buffer> */ = {
keysOnly: q.keysOnly
keysOnly: q.keysOnly,
offset: q.offset,
limit: q.limit,
filters: [
(e, cb) => cb(null, e.key.toString() !== shardKey.toString()),
(e, cb) => cb(null, e.key.toString() !== shardReadmeKey.toString())
]
}

if (q.prefix != null) {
// TODO: transform
tq.prefix = q.prefix
tq.filters.push((e, cb) => {
cb(null, this._invertKey(e.key).toString().startsWith(q.prefix))
})
}

if (q.filters != null) {
tq.filters = q.filters.map((f) => (e, cb) => {
const filters = q.filters.map((f) => (e, cb) => {
f(Object.assign({}, e, {
key: this._invertKey(e.key)
}), cb)
})
tq.filters = tq.filters.concat(filters)
}

if (q.orders != null) {
tq.orders = q.orders.map((o) => (res, cb) => {
const m = res.map((e) => {
return Object.assign({}, e, {
key: this._invertKey(e.key)
})
res.forEach((e) => { e.key = this._invertKey(e.key) })
o(res, (err, ordered) => {
if (err) {
return cb(err)
}
ordered.forEach((e) => { e.key = this._convertKey(e.key) })
cb(null, ordered)
})
o(m, cb)
})
}

if (q.offset != null) {
tq.offset = q.offset + 2
}

if (q.limit != null) {
tq.limit = q.limit + 2
}

return pull(
this.child.query(tq),
pull.filter((e) => {
if (e.key.toString() === shardKey.toString() ||
e.key.toString() === shardReadmeKey.toString()) {
return false
}
return true
})
)
return this.child.query(tq)
}

close (callback /* : Callback<void> */) /* : void */ {
Expand Down
3 changes: 1 addition & 2 deletions test/sharding.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ describe('ShardingStore', () => {
})
})

// TODO: fix query prefix and orders
describe.skip('interface-datastore', () => {
describe('interface-datastore', () => {
require('interface-datastore/src/tests')({
setup (callback) {
const shard = new sh.NextToLast(2)
Expand Down