Skip to content

Commit

Permalink
fix: adapt to latest db-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Dec 2, 2022
1 parent aa507ee commit 2e5da1e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
11 changes: 11 additions & 0 deletions src/datastore.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
dbQuery: DBQuery<ROW>,
_opt?: DatastoreDBOptions,
): Promise<RunQueryResult<ROW>> {
if (dbQuery._ids?.length) {
return {
rows: await this.getByIds(dbQuery.table, dbQuery._ids),
}
}

const q = dbQueryToDatastoreQuery(dbQuery, this.ds().createQuery(dbQuery.table))
const qr = await this.runDatastoreQuery<ROW>(q)

Expand Down Expand Up @@ -418,6 +424,11 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
return id?.toString()
}

override async createTable<ROW extends ObjectWithId>(
_table: string,
_schema: JsonSchemaObject<ROW>,
): Promise<void> {}

override async getTables(): Promise<string[]> {
const statsArray = await this.getAllStats()
// Filter out tables starting with `_` by default (internal Datastore tables)
Expand Down
6 changes: 3 additions & 3 deletions src/datastoreKeyValueDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
}

streamIds(table: string, limit?: number): ReadableTyped<string> {
const q = DBQuery.create(table)
const q = DBQuery.create<KVObject>(table)
.select(['id'])
.limit(limit || 0)

Expand All @@ -63,7 +63,7 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {

streamValues(table: string, limit?: number): ReadableTyped<Buffer> {
// `select v` doesn't work for some reason
const q = DBQuery.create(table).limit(limit || 0)
const q = DBQuery.create<KVObject>(table).limit(limit || 0)

const stream: ReadableTyped<string> = this.db
.streamQuery<KVObject>(q)
Expand All @@ -78,7 +78,7 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
}

streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple> {
const q = DBQuery.create(table).limit(limit || 0)
const q = DBQuery.create<KVObject>(table).limit(limit || 0)

const stream: ReadableTyped<string> = this.db
.streamQuery<KVObject>(q)
Expand Down
1 change: 1 addition & 0 deletions src/test/datastore.manual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const datastoreDB = new DatastoreDB({
// UPD 2021-08-05: nope, still needed
const features: CommonDBImplementationFeatures = {
// strongConsistency: false,
updateByQuery: false,
}
const quirks: CommonDBImplementationQuirks = {
// 2021-10-07: fails when set to 100, bumped up to 300
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -854,9 +854,9 @@
typescript "^4.0.2"

"@naturalcycles/db-lib@^8.46.1":
version "8.46.1"
resolved "https://registry.yarnpkg.com/@naturalcycles/db-lib/-/db-lib-8.46.1.tgz#eeee1bebc814e7662bb77aa3f21d35c187741069"
integrity sha512-HzOU4O92oI+4RG/pjANAei+rCBqV/KdxJAFiqaX6Pg8jKI6CfcVYy2NpdCZB7qBSaAgsoRaSb062nu9KlgT3QQ==
version "8.47.0"
resolved "https://registry.yarnpkg.com/@naturalcycles/db-lib/-/db-lib-8.47.0.tgz#dc6d7f3c3aa6d915803074adca72153fe80a9050"
integrity sha512-2ByptyD59MtjcuczofIkb2NpkjgCjUMXEZDEYWDko10Li1UjdFcpoPPOlulF2chhkwoV0VZiaHeDPw3Oyqod9A==
dependencies:
"@naturalcycles/js-lib" "^14.116.0"
"@naturalcycles/nodejs-lib" "^12.0.0"
Expand Down Expand Up @@ -904,9 +904,9 @@
yargs "^17.0.0"

"@naturalcycles/js-lib@^14.0.0", "@naturalcycles/js-lib@^14.116.0":
version "14.116.0"
resolved "https://registry.yarnpkg.com/@naturalcycles/js-lib/-/js-lib-14.116.0.tgz#a76ad1824f1cfd2ba4f10d99a54d2fa375eee84f"
integrity sha512-C+DcSlQcGtk+jqBrmWM9Dj67qaSxzk2gI68RsjfsvztMjxZsyu+Gz/VftVu8aVA+piyBJM3xkdAjNfNJZyRhVw==
version "14.117.0"
resolved "https://registry.yarnpkg.com/@naturalcycles/js-lib/-/js-lib-14.117.0.tgz#39ae15ac47b481c4169e86e692cc983cb3282b95"
integrity sha512-KfNW7wXu6XiClCqpHoutAHikEkfGv1jTQbpy14MUF9f4BIIm8lm2TOiNgBkMYXUnxW5+OPT7hiMRe0woo7QmIw==
dependencies:
tslib "^2.0.0"

Expand Down

0 comments on commit 2e5da1e

Please sign in to comment.