Skip to content

Commit 85bdc9d

Browse files
authored
Address #2954 for C++, C, Python, Node.js, and Java APIs (#2958)
1 parent 3c18730 commit 85bdc9d

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

src_cpp/include/py_database.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class PyDatabase {
1616

1717
static void initialize(py::handle& m);
1818

19+
static py::str getVersion();
20+
21+
static uint64_t getStorageVersion();
22+
1923
explicit PyDatabase(const std::string& databasePath, uint64_t bufferPoolSize,
2024
uint64_t maxNumThreads, bool compression, bool readOnly, uint64_t maxDBSize);
2125

src_cpp/py_database.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#include "include/py_database.h"
2-
#include "pandas/pandas_scan.h"
32

43
#include <memory>
54

5+
#include "main/version.h"
6+
#include "pandas/pandas_scan.h"
7+
68
using namespace kuzu::common;
79

810
void PyDatabase::initialize(py::handle& m) {
@@ -26,7 +28,17 @@ void PyDatabase::initialize(py::handle& m) {
2628
.def("scan_node_table_as_float", &PyDatabase::scanNodeTable<float>, py::arg("table_name"),
2729
py::arg("prop_name"), py::arg("indices"), py::arg("np_array"), py::arg("num_threads"))
2830
.def("scan_node_table_as_bool", &PyDatabase::scanNodeTable<bool>, py::arg("table_name"),
29-
py::arg("prop_name"), py::arg("indices"), py::arg("np_array"), py::arg("num_threads"));
31+
py::arg("prop_name"), py::arg("indices"), py::arg("np_array"), py::arg("num_threads"))
32+
.def_static("get_version", &PyDatabase::getVersion)
33+
.def_static("get_storage_version", &PyDatabase::getStorageVersion);
34+
}
35+
36+
py::str PyDatabase::getVersion() {
37+
return py::str(Version::getVersion());
38+
}
39+
40+
uint64_t PyDatabase::getStorageVersion() {
41+
return Version::getStorageVersion();
3042
}
3143

3244
PyDatabase::PyDatabase(const std::string& databasePath, uint64_t bufferPoolSize,

src_py/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@
5151
from .query_result import *
5252
from .types import *
5353

54+
def __getattr__(name):
55+
if name == "version":
56+
return Database.get_version()
57+
elif name == "storage_version":
58+
return Database.get_storage_version()
59+
else:
60+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
61+
62+
5463
# Restore the original dlopen flags
5564
if sys.platform == "linux":
5665
sys.setdlopenflags(original_dlopen_flags)

src_py/database.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,28 @@ def __init__(self, database_path, buffer_pool_size=0, max_num_threads=0, compres
5050
self._database = None
5151
if not lazy_init:
5252
self.init_database()
53+
54+
def get_version():
55+
"""
56+
Get the version of the database.
57+
58+
Returns
59+
-------
60+
str
61+
The version of the database.
62+
"""
63+
return _kuzu.Database.get_version()
64+
65+
def get_storage_version():
66+
"""
67+
Get the storage version of the database.
68+
69+
Returns
70+
-------
71+
int
72+
The storage version of the database.
73+
"""
74+
return _kuzu.Database.get_storage_version()
5375

5476
def __getstate__(self):
5577
state = {

test/test_version.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def test_version():
2+
import kuzu
3+
assert kuzu.version != ""
4+
assert kuzu.storage_version > 0

0 commit comments

Comments
 (0)