-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
201 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ bazel-* | |
|
||
test_temp/ | ||
build/ | ||
cmake-build-debug/ | ||
|
||
### Python | ||
# Byte-compiled / optimized / DLL files | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tools/python_api/py_database.cpp → tools/python_api/src_cpp/py_database.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from ._kuzu import * | ||
# The following imports will override C++ implementations with Python | ||
# implementations. | ||
from .connection import * | ||
from .query_result import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from .query_result import QueryResult | ||
from . import _kuzu | ||
|
||
|
||
class Connection: | ||
def __init__(self, database, num_threads=0): | ||
self.database = database | ||
self._connection = _kuzu.Connection(database, num_threads) | ||
|
||
def set_max_threads_for_exec(self, num_threads): | ||
self._connection.set_max_threads_for_exec(num_threads) | ||
|
||
def execute(self, query, parameters=[]): | ||
return QueryResult(self, self._connection.execute(query, parameters)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class QueryResult: | ||
def __init__(self, connection, query_result): | ||
self.connection = connection | ||
self._query_result = query_result | ||
self.is_closed = False | ||
|
||
def __del__(self): | ||
self.close() | ||
|
||
def check_for_query_result_close(self): | ||
if self.is_closed: | ||
raise Exception("Query result is closed") | ||
|
||
def has_next(self): | ||
self.check_for_query_result_close() | ||
return self._query_result.hasNext() | ||
|
||
def get_next(self): | ||
self.check_for_query_result_close() | ||
return self._query_result.getNext() | ||
|
||
def write_to_csv(self, filename, delimiter=',', escapeCharacter='"', newline='\n'): | ||
self.check_for_query_result_close() | ||
self._query_result.writeToCSV( | ||
filename, delimiter, escapeCharacter, newline) | ||
|
||
def close(self): | ||
self._query_result.close() | ||
# Allows the connection to be garbage collected if the query result | ||
# is closed manually by the user. | ||
self.connection = None | ||
self.is_closed = True | ||
|
||
def get_as_df(self): | ||
self.check_for_query_result_close() | ||
return self._query_result.getAsDF() | ||
|
||
def get_column_data_types(self): | ||
self.check_for_query_result_close() | ||
return self._query_result.getColumnDataTypes() | ||
|
||
def get_column_names(self): | ||
self.check_for_query_result_close() | ||
return self._query_result.getColumnNames() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
from tools.python_api import _kuzu as kuzu | ||
import sys | ||
sys.path.append('../build/') | ||
import kuzu | ||
|
||
databaseDir = "path to database file" | ||
db = kuzu.database(databaseDir) | ||
conn = kuzu.connection(db) | ||
db = kuzu.Database(databaseDir) | ||
conn = kuzu.Connection(db) | ||
query = "MATCH (a:person) RETURN *;" | ||
result = conn.execute(query) | ||
while result.hasNext(): | ||
print(result.getNext()) | ||
while result.has_next(): | ||
print(result.get_next()) | ||
result.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.