Skip to content

Commit e2311da

Browse files
authored
Merge pull request #102 from semi-technologies/node_name-consistency_level-WEAVIATE-462
Add support for node_name and consistency_level get by id query params
2 parents 451b2f3 + 9c03533 commit e2311da

File tree

5 files changed

+72
-3
lines changed

5 files changed

+72
-3
lines changed

data/getterById.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ export default class GetterById {
2525

2626
withVector = () => this.extendAdditionals("vector");
2727

28+
withConsistencyLevel = (cl) => {
29+
this.consistencyLevel = cl;
30+
return this;
31+
};
32+
33+
withNodeName = (nodeName) => {
34+
this.nodeName = nodeName;
35+
return this;
36+
};
37+
2838
validateId = () => {
2939
if (this.id == undefined || this.id == null || this.id.length == 0) {
3040
this.errors = [
@@ -38,6 +48,11 @@ export default class GetterById {
3848
this.validateId();
3949
};
4050

51+
buildPath = () => {
52+
return this.objectsPath.buildGetOne(this.id, this.className,
53+
this.additionals, this.consistencyLevel, this.nodeName)
54+
}
55+
4156
do = () => {
4257
this.validate();
4358
if (this.errors.length > 0) {
@@ -46,7 +61,7 @@ export default class GetterById {
4661
);
4762
}
4863

49-
return this.objectsPath.buildGetOne(this.id, this.className, this.additionals)
64+
return this.buildPath()
5065
.then(this.client.get);
5166
};
5267
}

data/journey.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,40 @@ describe("data", () => {
584584
.catch((e) => fail("it should not have errord: " + e));
585585
});
586586

587+
it("forms a get by id query with node_name set", () => {
588+
const id = "1565c06c-463f-466c-9092-5930dbac3887";
589+
590+
return client.data
591+
.getterById()
592+
.withClassName(thingClassName)
593+
.withId(id)
594+
.withVector()
595+
.withNodeName("node1")
596+
.buildPath()
597+
.then(path => {
598+
expect(path).toContain("?include=vector");
599+
expect(path).toContain("&node_name=node1");
600+
})
601+
.catch((e) => fail("it should not have errord: " + e));
602+
})
603+
604+
it("forms a get by id query with consistency_level set", () => {
605+
const id = "1565c06c-463f-466c-9092-5930dbac3887";
606+
607+
return client.data
608+
.getterById()
609+
.withClassName(thingClassName)
610+
.withId(id)
611+
.withVector()
612+
.withConsistencyLevel(weaviate.replication.ConsistencyLevel.QUORUM)
613+
.buildPath()
614+
.then(path => {
615+
expect(path).toContain("?include=vector");
616+
expect(path).toContain("consistency_level=QUORUM");
617+
})
618+
.catch((e) => fail("it should not have errord: " + e));
619+
})
620+
587621
it("tears down and cleans up", () => {
588622
return Promise.all([
589623
client.schema.classDeleter().withClassName(thingClassName).do(),

data/path.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ export class ObjectsPath {
1717
buildCheck(id, className) {
1818
return this.build({id, className}, [this.addClassNameDeprecatedNotSupportedCheck, this.addId]);
1919
}
20-
buildGetOne(id, className, additionals) {
21-
return this.build({id, className, additionals}, [this.addClassNameDeprecatedNotSupportedCheck, this.addId, this.addQueryParams]);
20+
buildGetOne(id, className, additionals, consistencyLevel, nodeName) {
21+
return this.build({id, className, additionals, consistencyLevel, nodeName},
22+
[this.addClassNameDeprecatedNotSupportedCheck, this.addId, this.addQueryParams]);
2223
}
2324
buildGet(className, limit, additionals) {
2425
return this.build({className, limit, additionals}, [this.addQueryParamsForGet]);
@@ -73,6 +74,12 @@ export class ObjectsPath {
7374
if (Array.isArray(params.additionals) && params.additionals.length > 0) {
7475
queryParams.push(`include=${params.additionals.join(",")}`);
7576
}
77+
if (isValidStringProperty(params.nodeName)) {
78+
queryParams.push(`node_name=${params.nodeName}`);
79+
}
80+
if (isValidStringProperty(params.consistencyLevel)) {
81+
queryParams.push(`consistency_level=${params.consistencyLevel}`);
82+
}
7683
if (queryParams.length > 0) {
7784
return `${path}?${queryParams.join("&")}`;
7885
}

data/replication/consts.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const ConsistencyLevel = {
2+
ONE: "ONE",
3+
QUORUM: "QUORUM",
4+
ALL: "ALL",
5+
};
6+
7+
const replicationConsts = {
8+
ConsistencyLevel,
9+
};
10+
11+
export default replicationConsts;

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import batchConsts from "./batch/consts.js";
1313
import filtersConsts from "./filters/consts.js";
1414
import cluster from "./cluster/index.js";
1515
import clusterConsts from "./cluster/consts.js";
16+
import replicationConsts from "./data/replication/consts.js";
1617

1718
const app = {
1819
client: function (params) {
@@ -47,6 +48,7 @@ const app = {
4748
batch: batchConsts,
4849
filters: filtersConsts,
4950
cluster: clusterConsts,
51+
replication: replicationConsts,
5052
};
5153

5254
function initDbVersionProvider(conn) {

0 commit comments

Comments
 (0)