-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
61 lines (48 loc) · 2.24 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const { expect } = require('chai');
const { query, Session } = require(".");
describe('chDB Queries', function () {
it('should return version, greeting message, and chdb() using standalone query', function () {
const ret = query("SELECT version(), 'Hello chDB', chdb()", "CSV");
console.log("Standalone Query Result:", ret);
expect(ret).to.be.a('string');
expect(ret).to.include('Hello chDB');
});
it('should throw an error when querying a non-existent table', function () {
expect(() => {
query("SELECT * FROM non_existent_table;", "CSV");
}).to.throw(Error, /Unknown table expression identifier/);
});
describe('Session Queries', function () {
let session;
before(function () {
// Create a new session instance before running the tests
session = new Session("./chdb-node-tmp");
});
after(function () {
// Clean up the session after all tests are done
session.cleanup();
});
it('should return a simple query result from session', function () {
const ret = session.query("SELECT 123", "CSV");
console.log("Session Query Result:", ret);
expect(ret).to.be.a('string');
expect(ret).to.include('123');
});
it('should create database and table, then insert and query data', function () {
session.query("CREATE DATABASE IF NOT EXISTS testdb;" +
"CREATE TABLE IF NOT EXISTS testdb.testtable (id UInt32) ENGINE = MergeTree() ORDER BY id;");
session.query("USE testdb; INSERT INTO testtable VALUES (1), (2), (3);");
const ret = session.query("SELECT * FROM testtable;", "CSV");
console.log("Session Query Result:", ret);
expect(ret).to.be.a('string');
expect(ret).to.include('1');
expect(ret).to.include('2');
expect(ret).to.include('3');
});
it('should throw an error when querying a non-existent table', function () {
expect(() => {
session.query("SELECT * FROM non_existent_table;", "CSV");
}).to.throw(Error, /Unknown table expression identifier/);
});
});
});