Skip to content

Commit

Permalink
Fix embedded
Browse files Browse the repository at this point in the history
Signed-off-by: Jin Hai <[email protected]>
  • Loading branch information
JinHai-CN committed Oct 16, 2024
1 parent adfab3d commit 15075ee
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion python/infinity_embedded/infinity.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, uri):
self.uri = uri

@abstractmethod
def create_database(self, db_name, options=None):
def create_database(self, db_name, options=None, comment: str = None):
pass

@abstractmethod
Expand Down
9 changes: 7 additions & 2 deletions python/infinity_embedded/local_infinity/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,15 @@ def convert_res(self, res, has_db_names=False, has_table_names=False, has_result
return LocalQueryResult(PyErrorCode(res.error_code.value), res.error_msg, index_names=res.names)
return LocalQueryResult(PyErrorCode(res.error_code.value), res.error_msg)

def create_database(self, db_name: str, conflict_type: ConflictType = ConflictType.kError):
def create_database(self, db_name: str, conflict_type: ConflictType = ConflictType.kError, comment: str = None):
create_database_options = CreateDatabaseOptions()
create_database_options.conflict_type = conflict_type
return self.convert_res(self.client.CreateDatabase(db_name, create_database_options))
db_comment: str = None
if comment is None:
db_comment = ""
else:
db_comment = comment
return self.convert_res(self.client.CreateDatabase(db_name, create_database_options, db_comment))

def drop_database(self, db_name: str, conflict_type: ConflictType = ConflictType.kError):
drop_database_options = DropDatabaseOptions()
Expand Down
3 changes: 2 additions & 1 deletion python/infinity_embedded/local_infinity/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@


class LocalDatabase(Database, ABC):
def __init__(self, conn, name: str):
def __init__(self, conn, name: str, comment: str = None):
self._conn = conn
self._db_name = name
self._db_comment = comment

def create_table(self, table_name: str, columns_definition,
conflict_type: ConflictType = ConflictType.Error):
Expand Down
4 changes: 2 additions & 2 deletions python/infinity_embedded/local_infinity/infinity.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def check_connect(self):
raise Exception("Local infinity is not connected")

@name_validity_check("db_name", "DB")
def create_database(self, db_name: str, conflict_type: ConflictType = ConflictType.Error):
def create_database(self, db_name: str, conflict_type: ConflictType = ConflictType.Error, comment: str = None):
self.check_connect()
create_database_conflict: LocalConflictType
if conflict_type == ConflictType.Error:
Expand All @@ -50,7 +50,7 @@ def create_database(self, db_name: str, conflict_type: ConflictType = ConflictTy
create_database_conflict = LocalConflictType.kReplace
else:
raise InfinityException(ErrorCode.INVALID_CONFLICT_TYPE, "Invalid conflict type")
res = self._client.create_database(db_name, create_database_conflict)
res = self._client.create_database(db_name, create_database_conflict, comment)

if res.error_code == ErrorCode.OK:
return LocalDatabase(self._client, db_name)
Expand Down
6 changes: 5 additions & 1 deletion src/embedded_infinity/wrap_infinity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ WrapQueryResult WrapShowDatabase(Infinity &instance, const String &db_name) {
if (query_result.IsOk()) {
SharedPtr<DataBlock> data_block = query_result.result_table_->GetDataBlockById(0);
auto row_count = data_block->row_count();
if (row_count != 3) {
if (row_count != 4) {
String error_message = "ShowDatabase: query result is invalid.";
UnrecoverableError(error_message);
}
Expand All @@ -593,6 +593,10 @@ WrapQueryResult WrapShowDatabase(Infinity &instance, const String &db_name) {
Value value = data_block->GetValue(1, 2);
result.table_count = std::stol(value.GetVarchar());
}
{
Value value = data_block->GetValue(1, 3);
result.database_comment = value.GetVarchar();
}
}
return result;
}
Expand Down
5 changes: 3 additions & 2 deletions src/embedded_infinity/wrap_infinity.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export struct WrapQueryResult {
// show database
String database_name;
String store_dir;
String database_comment;
BigIntT table_count;

WrapQueryResult() = default;
Expand Down Expand Up @@ -289,9 +290,9 @@ export struct WrapUpdateExpr {
UpdateExpr *GetUpdateExpr(Status &status);
};

export WrapQueryResult WrapCreateDatabase(Infinity &instance, const String &db_name, const CreateDatabaseOptions &options);
export WrapQueryResult WrapCreateDatabase(Infinity &instance, const String &db_name, const CreateDatabaseOptions &options, const String &comment);

export WrapQueryResult WrapDropDatabase(Infinity &instance, const String &db_name, const DropDatabaseOptions &options, const String &comment);
export WrapQueryResult WrapDropDatabase(Infinity &instance, const String &db_name, const DropDatabaseOptions &options);

export WrapQueryResult WrapListDatabases(Infinity &instance);

Expand Down

0 comments on commit 15075ee

Please sign in to comment.