Skip to content

Commit 1513fad

Browse files
authored
feat(types): add most of type supports for the driver (#48)
Signed-off-by: Daniel Boll <[email protected]>
1 parent 6fbe40f commit 1513fad

30 files changed

+1089
-165
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ scylla = { version = "0.13.1", features = [
2626
uuid = { version = "1.10", features = ["serde", "v4", "fast-rng"] }
2727
serde_json = "1.0"
2828
serde = { version = "1.0", features = ["derive"] }
29-
openssl = { version = "0.10.66", features = ["vendored"] }
29+
openssl = { version = "0.10", features = ["vendored"] }
3030

3131
[build-dependencies]
3232
napi-build = "2"

examples/custom-types/bigint.mts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Cluster } from "../../index.js";
2+
3+
const nodes = process.env.CLUSTER_NODES?.split(",") ?? ["127.0.0.1:9042"];
4+
5+
console.log(`Connecting to ${nodes}`);
6+
7+
const cluster = new Cluster({ nodes });
8+
const session = await cluster.connect();
9+
10+
await session.execute(
11+
"CREATE KEYSPACE IF NOT EXISTS bigints WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }",
12+
);
13+
await session.useKeyspace("bigints");
14+
15+
await session.execute(
16+
"CREATE TABLE IF NOT EXISTS bigints (a bigint, primary key (a))",
17+
);
18+
19+
await session.execute("INSERT INTO bigints (a) VALUES (?)", [1238773128n]);
20+
21+
const results = await session.execute("SELECT a FROM bigints");
22+
console.log(results);

examples/custom-types/floats.mts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Cluster, Float } from "../../index.js";
2+
3+
const nodes = process.env.CLUSTER_NODES?.split(",") ?? ["127.0.0.1:9042"];
4+
5+
console.log(`Connecting to ${nodes}`);
6+
7+
const cluster = new Cluster({ nodes });
8+
const session = await cluster.connect();
9+
10+
await session.execute(
11+
"CREATE KEYSPACE IF NOT EXISTS floats WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }",
12+
);
13+
await session.useKeyspace("floats");
14+
15+
await session.execute(
16+
"CREATE TABLE IF NOT EXISTS floats (a float, primary key (a))",
17+
);
18+
19+
await session.execute("INSERT INTO floats (a) VALUES (?)", [new Float(1.1)]);
20+
21+
const results = await session.execute("SELECT a FROM floats");
22+
console.log(results);

examples/custom-types/list.mts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Cluster, List, Uuid } from "../../index.js";
2+
3+
const nodes = process.env.CLUSTER_NODES?.split(",") ?? ["127.0.0.1:9042"];
4+
5+
console.log(`Connecting to ${nodes}`);
6+
7+
const cluster = new Cluster({ nodes });
8+
const session = await cluster.connect();
9+
10+
await session.execute(
11+
"CREATE KEYSPACE IF NOT EXISTS lists WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }",
12+
);
13+
await session.useKeyspace("lists");
14+
15+
await session.execute(
16+
"CREATE TABLE IF NOT EXISTS lists (a uuid, b list<int>, primary key (a))",
17+
);
18+
19+
// NOTE: driver is not throwing errors if the return of the function is not used.
20+
await session.execute("INSERT INTO lists (a, b) VALUES (?, ?)", [
21+
Uuid.randomV4(),
22+
new List<number>([1, 2, 3]),
23+
]);
24+
25+
const results = await session.execute("SELECT * FROM lists");
26+
console.log(results);

examples/custom-types/map.mts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Cluster, Map, Uuid } from "../../index.js";
2+
3+
const nodes = process.env.CLUSTER_NODES?.split(",") ?? ["127.0.0.1:9042"];
4+
5+
console.log(`Connecting to ${nodes}`);
6+
7+
const cluster = new Cluster({ nodes });
8+
const session = await cluster.connect();
9+
10+
await session.execute(
11+
"CREATE KEYSPACE IF NOT EXISTS maps WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }",
12+
);
13+
await session.useKeyspace("maps");
14+
15+
await session.execute(
16+
"CREATE TABLE IF NOT EXISTS maps (a uuid, b map<text, int>, primary key (a))",
17+
);
18+
19+
await session.execute("INSERT INTO maps (a, b) VALUES (?, ?)", [
20+
Uuid.randomV4(),
21+
new Map<string, number>([
22+
["a", 1],
23+
["b", 2],
24+
["c", 3],
25+
]),
26+
]);
27+
28+
const results = await session.execute("SELECT * FROM maps");
29+
console.log(results);

examples/custom-types/set.mts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Cluster, Set, Uuid } from "../../index.js";
2+
3+
const nodes = process.env.CLUSTER_NODES?.split(",") ?? ["127.0.0.1:9042"];
4+
5+
console.log(`Connecting to ${nodes}`);
6+
7+
const cluster = new Cluster({ nodes });
8+
const session = await cluster.connect();
9+
10+
await session.execute(
11+
"CREATE KEYSPACE IF NOT EXISTS sets WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }",
12+
);
13+
await session.useKeyspace("sets");
14+
15+
await session.execute(
16+
"CREATE TABLE IF NOT EXISTS sets (a uuid, b set<int>, primary key (a))",
17+
);
18+
19+
await session.execute("INSERT INTO sets (a, b) VALUES (?, ?)", [
20+
Uuid.randomV4(),
21+
new Set<number>([1, 2, 3, 1]),
22+
]);
23+
24+
const results = await session.execute("SELECT * FROM sets");
25+
console.log(results);

examples/custom-types/tuple.mts

Whitespace-only changes.

examples/udt.mts renamed to examples/custom-types/udt.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Cluster } from "../index.js";
1+
import { Cluster } from "../../index.js";
22

33
const nodes = process.env.CLUSTER_NODES?.split(",") ?? ["127.0.0.1:9042"];
44

examples/custom-types/uuid.mts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Cluster, Uuid } from "../../index.js";
2+
3+
const nodes = process.env.CLUSTER_NODES?.split(",") ?? ["127.0.0.1:9042"];
4+
5+
console.log(`Connecting to ${nodes}`);
6+
7+
const cluster = new Cluster({ nodes });
8+
const session = await cluster.connect();
9+
10+
await session.execute(
11+
"CREATE KEYSPACE IF NOT EXISTS uuids WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }",
12+
);
13+
await session.useKeyspace("uuids");
14+
15+
await session.execute(
16+
"CREATE TABLE IF NOT EXISTS uuids (a uuid, primary key (a))",
17+
);
18+
19+
await session.execute("INSERT INTO uuids (a) VALUES (?)", [Uuid.randomV4()]);
20+
21+
const results = await session.execute("SELECT a FROM uuids");
22+
console.log(results);

examples/custom-types/varint.mts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Cluster, Varint } from "../../index.js";
2+
3+
const nodes = process.env.CLUSTER_NODES?.split(",") ?? ["127.0.0.1:9042"];
4+
5+
console.log(`Connecting to ${nodes}`);
6+
7+
const cluster = new Cluster({ nodes });
8+
const session = await cluster.connect();
9+
10+
await session.execute(
11+
"CREATE KEYSPACE IF NOT EXISTS varints WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }",
12+
);
13+
await session.useKeyspace("varints");
14+
15+
await session.execute(
16+
"CREATE TABLE IF NOT EXISTS varints (a varint, primary key (a))",
17+
);
18+
19+
await session.execute("INSERT INTO varints (a) VALUES (?)", [
20+
new Varint([0x00, 0x01, 0x02]),
21+
]);
22+
23+
const results = await session.execute("SELECT a FROM varints");
24+
console.log(results);

0 commit comments

Comments
 (0)