时序数据库 quasardb 入门

发布时间 2023-06-28 11:25:27作者: bonelee

到:https://download.quasar.ai/quasardb/3.9/3.9.9/server/

下载最新版: https://download.quasar.ai/quasardb/3.9/3.9.9/server/qdb-3.9.9-windows-64bit-setup.exe

然后安装,记得先不勾选安全连接。安装成功以后,自己去操作下:

>"C:\Program Files\quasardb\bin\qdbsh.exe"
quasardb shell version 3.9.9 build fc2829ecc 2021-07-01 09:13:49 +0200
Copyright (c) 2009-2021, quasardb SAS. All rights reserved.

Need some help? Check out our documentation here:  https://doc.quasardb.net

qdbsh > CREATE TABLE stocks (close DOUBLE)

qdbsh > INSERT INTO stocks ($timestamp, close) VALUES (2017-01-01, 1.0), (2017-01-02, 2.0), (2017-01-03, 3.0)

qdbsh > select * from stocks in range(2017-01-01, 2017-01-10)
$timestamp                       $table            close
---------------------------------------------------------
2017-01-01T00:00:00.000000000Z   stocks                1
2017-01-02T00:00:00.000000000Z   stocks                2
2017-01-03T00:00:00.000000000Z   stocks                3

Returned 3 rows in 6,441 us
Scanned 3 points in 6,441 us (465 rows/sec)

qdbsh > show stocks
Shard size: 86400000 ms
2 columns
 0. timestamp index
 1. close - double (0)

  

为了使用C api操作数据:

需要先下载api:

https://download.quasar.ai/quasardb/3.9/3.9.9/api/c/

操作代码:

#pragma comment(lib, "D:\\source\\qdb-3.9.9-windows-64bit-c-api\\lib\\qdb_api.lib")

#include <qdb/client.h>
#include <qdb/tag.h>
#include <qdb/ts.h>
#include <stdio.h>

#define EXIT_FAILURE 1

int main() {
	// We first need to open a handle, which is is the memory structure that
	// QuasarDB uses to maintain connection state.
	qdb_handle_t handle;
	qdb_error_t error = qdb_open(&handle, qdb_p_tcp);
	if (QDB_FAILURE(error)) return EXIT_FAILURE;

	// Now that we have opened the handle, we can tell it to establish a connection
	// with the cluster.
	error = qdb_connect(handle, "qdb://127.0.0.1:2836");
	if (QDB_FAILURE(error)) {
		printf("Connect db failed!Error code:%d\n", error);
		return EXIT_FAILURE;
	}
	// Initialize our columns definitions
	const qdb_ts_column_info_t columns[3] = {
		{.name = "open",.type = qdb_ts_column_double},  //
		{.name = "close",.type = qdb_ts_column_double}, //
		{.name = "volume",.type = qdb_ts_column_int64}  //
	};
	const int columns_count = sizeof(columns) / sizeof(qdb_ts_column_info_t);

	// Now create the table with the default shard size
	qdb_error_t error2 = qdb_ts_create(handle, "stocks4test", qdb_d_default_shard_size, columns, columns_count);
	if (QDB_FAILURE(error2)) {
		printf("Insert data failed! Error code: %d\n", error2);
		return EXIT_FAILURE;
	}
	printf("Insert data success!\n");
}

  

可以看到操作成功!