Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ jobs:

- deploy-maven-jni-snapshot-unix

# - deploy-clib-snapshot-unix
- deploy-clib-snapshot-unix
# - test-clib-assembly-linux:
# target-arch: arm64

Expand All @@ -551,7 +551,7 @@ jobs:

- deploy-maven-jni-snapshot-unix

# - deploy-clib-snapshot-unix
- deploy-clib-snapshot-unix
# - test-clib-assembly-linux:
# target-arch: x86_64

Expand All @@ -575,7 +575,7 @@ jobs:

# - run: brew install cmake

# - deploy-clib-snapshot-unix
- deploy-clib-snapshot-unix
# - test-clib-assembly-mac:
# target-arch: arm64

Expand All @@ -599,7 +599,7 @@ jobs:

# - run: brew install cmake

# - deploy-clib-snapshot-unix
- deploy-clib-snapshot-unix
# - test-clib-assembly-mac:
# target-arch: x86_64

Expand All @@ -620,8 +620,8 @@ jobs:

- run: .circleci\windows\java\deploy_snapshot.bat

# - run: .circleci\windows\clib\deploy_snapshot.bat
# - run: .circleci\windows\clib\test_assembly.bat
- run: .circleci\windows\clib\deploy_snapshot.bat
- run: .circleci\windows\clib\test_assembly.bat

# - run: .circleci\windows\cpp\deploy_snapshot.bat
# - run: .circleci\windows\cpp\test_assembly.bat
Expand Down Expand Up @@ -728,7 +728,7 @@ jobs:
bazel-arch: arm64
- deploy-pip-release-unix
- deploy-maven-jni-release-unix
# - deploy-clib-release-unix
- deploy-clib-release-unix
# - deploy-cpp-release-unix

# - install-libicu-linux
Expand All @@ -742,7 +742,7 @@ jobs:
bazel-arch: amd64
- deploy-pip-release-unix
- deploy-maven-jni-release-unix
# - deploy-clib-release-unix
- deploy-clib-release-unix
# - deploy-cpp-release-unix

# - install-libicu-linux
Expand All @@ -756,7 +756,7 @@ jobs:
bazel-arch: arm64
- deploy-pip-release-unix
- deploy-maven-jni-release-unix
# - deploy-clib-release-unix
- deploy-clib-release-unix
# - deploy-cpp-release-unix
# - deploy-dotnet-runtime-release-unix

Expand All @@ -769,7 +769,7 @@ jobs:
bazel-arch: amd64
- deploy-pip-release-unix
- deploy-maven-jni-release-unix
# - deploy-clib-release-unix
- deploy-clib-release-unix
# - deploy-cpp-release-unix
# - deploy-dotnet-runtime-release-unix

Expand All @@ -781,7 +781,7 @@ jobs:
- run: .circleci\windows\prepare.bat
- run: .circleci\windows\python\deploy_release.bat
- run: .circleci\windows\java\deploy_release.bat
# - run: .circleci\windows\clib\deploy_release.bat
- run: .circleci\windows\clib\deploy_release.bat
# - run: .circleci\windows\cpp\deploy_release.bat
# - run: .circleci\windows\csharp\deploy_release.bat

Expand Down
28 changes: 14 additions & 14 deletions .factory/automation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,20 @@ build:
# tool/test/stop-cluster-servers.sh
# exit $TEST_SUCCESS

# test-c-integration:
# image: typedb-ubuntu-20.04 # Ubuntu 20.04 has GLIBC version 2.31 (2020) which we should verify to compile against
# dependencies:
# - build
# command: |
# export ARTIFACT_USERNAME=$REPO_TYPEDB_USERNAME
# export ARTIFACT_PASSWORD=$REPO_TYPEDB_PASSWORD
# bazel run @typedb_dependencies//tool/bazelinstall:remote_cache_setup.sh
# bazel run @typedb_dependencies//distribution/artifact:create-netrc
# tool/test/start-community-server.sh &&
# bazel test //c/tests/integration:test-driver --test_output=errors &&
# export TEST_SUCCESS=0 || export TEST_SUCCESS=1
# tool/test/stop-community-server.sh
# exit $TEST_SUCCESS
test-c-integration:
image: typedb-ubuntu-20.04 # Ubuntu 20.04 has GLIBC version 2.31 (2020) which we should verify to compile against
dependencies:
- build
command: |
export ARTIFACT_USERNAME=$REPO_TYPEDB_USERNAME
export ARTIFACT_PASSWORD=$REPO_TYPEDB_PASSWORD
bazel run @typedb_dependencies//tool/bazelinstall:remote_cache_setup.sh
bazel run @typedb_dependencies//distribution/artifact:create-netrc
tool/test/start-community-server.sh &&
bazel test //c/tests/integration:test-driver --test_output=errors &&
export TEST_SUCCESS=0 || export TEST_SUCCESS=1
tool/test/stop-community-server.sh
exit $TEST_SUCCESS

test-java-integration:
image: typedb-ubuntu-22.04
Expand Down
4 changes: 4 additions & 0 deletions RELEASE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ Documentation: https://typedb.com/docs/drivers/
npm install typedb-driver-http@{version}
```

### C driver

Compiled distributions comprising headers and shared libraries available at: https://cloudsmith.io/~typedb/repos/public-release/packages/?q=name:^typedb-driver-clib+version:{version}

{ release notes }
17 changes: 10 additions & 7 deletions c/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# TypeDB C Driver
The TypeDB C driver provides C bindings to the rust driver.
It also serves as the base on which the other wrapper drivers are built.
It is not very ergonomic to be used directly as a C driver. That is future work.

## Usage
The driver is distributed as an archive containing the headers & a shared library.
Expand All @@ -22,16 +23,19 @@ Code examples can be found in the [integration tests](https://github.com/typedb/

Functions parameters & return values are either primitives or pointers to opaque structs, e.g.:
```c
Driver *driver_open_core(const char *address);
struct TypeDBDriver *driver_open(const char *address,
const struct Credentials *credentials,
const struct DriverOptions *driver_options);
```

These pointers are then used for further operations:
```c
char* dbName = "hello";
Driver *driver = driver_open_core("127.0.0.1:1729");
DatabaseManager* databaseManager = database_manager_new(driver);
databases_create(databaseManager, dbName);
Database* database = databases_get(databaseManager, dbName);
DriverOptions* options = driver_options_new(false, NULL);;;
Credentials* creds = credentials_new(username, password);
TypeDBDriver* driver = driver_open(address, creds, options);
databases_create(driver, dbName);
Database* database = databases_get(driver, dbName);
char* gotName = database_name(database);
assert(0 == strcmp(gotName, dbName));
...
Expand All @@ -46,7 +50,6 @@ Types which have `*_close` methods will be freed on close.
...
string_free(gotName);
database_close(database);
database_manager_drop(databaseManager);
driver_close(connection);
```

Expand All @@ -68,7 +71,7 @@ if (check_error()) {
Iterators can be forwarded with the `*_iterator_next` method,
which returns `NULL` when the end has been reached.
```c
DatabaseIterator* it = databases_all(databaseManager);
DatabaseIterator* it = databases_all(driver);
Database* database = NULL;
while (NULL != (database = database_iterator_next(it))) {
...
Expand Down
30 changes: 20 additions & 10 deletions c/tests/assembly/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <typedb_driver.h>

const char* TYPEDB_CORE_ADDRESS = "127.0.0.1:1729";
const char* TYPEDB_CORE_USERNAME = "admin";
const char* TYPEDB_CORE_PASSWORD = "password";
const char* DRIVER_LANG = "c";


Expand All @@ -40,34 +42,42 @@ bool check_error_may_print(const char* filename, int lineno) {
}

#define FAILED() check_error_may_print(__FILE__, __LINE__)
TypeDBDriver* driver_open_for_tests(const char* address, const char* username, const char* password) {
DriverOptions* options = NULL;
Credentials* creds = credentials_new(username, password);
if (check_error_may_print(__FILE__, __LINE__)) goto cleanup;
options = driver_options_new(false, NULL);;
if (check_error_may_print(__FILE__, __LINE__)) goto cleanup;
TypeDBDriver* driver = driver_open_with_description(address, creds, options, DRIVER_LANG);
cleanup:
driver_options_drop(options);
credentials_drop(creds);

return driver;
}

int main() {
const char databaseName[] = "test_assembly_clib";

Connection* connection = NULL;
DatabaseManager* databaseManager = NULL;
TypeDBDriver* driver = NULL;

bool success = false;

connection = driver_open_core(TYPEDB_CORE_ADDRESS, DRIVER_LANG);
if (FAILED()) goto cleanup;

databaseManager = database_manager_new(connection);
driver = driver_open_for_tests(TYPEDB_CORE_ADDRESS, TYPEDB_CORE_USERNAME, TYPEDB_CORE_PASSWORD);
if (FAILED()) goto cleanup;

databases_create(databaseManager, databaseName);
databases_create(driver, databaseName);
if (FAILED()) goto cleanup;

if (!databases_contains(databaseManager, databaseName)) {
if (!databases_contains(driver, databaseName)) {
fprintf(stderr, "databases_contains(\'%s\') failed\n", databaseName);
goto cleanup;
}

success = true;
cleanup:
check_error_may_print(__FILE__, __LINE__);
database_manager_drop(databaseManager);
driver_close(connection);
driver_close(driver);

printf("Success: %s\n", success ? "true" : "false");
return success ? 0 : 1;
Expand Down
28 changes: 24 additions & 4 deletions c/tests/integration/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "common.h"

const char* TYPEDB_CORE_ADDRESS = "127.0.0.1:1729";
const char* TYPEDB_CORE_USERNAME = "admin";
const char* TYPEDB_CORE_PASSWORD = "password";
const char* DRIVER_LANG = "c";

bool check_error_may_print(const char* filename, int lineno) {
Expand All @@ -38,9 +40,27 @@ bool check_error_may_print(const char* filename, int lineno) {
} else return false;
}

void delete_database_if_exists(DatabaseManager* databaseManager, const char* name) {
if (NULL != databaseManager && databases_contains(databaseManager, name)) {
Database* database = databases_get(databaseManager, name);
database_delete(database);
void delete_database_if_exists(TypeDBDriver* driver, const char* name) {
if (driver == NULL) return;
bool contains = databases_contains(driver, name);
if (check_error_may_print(__FILE__, __LINE__)) return;
if (contains) {
const Database* db = databases_get(driver, name);
if (check_error_may_print(__FILE__, __LINE__)) return;
database_delete(db);
}
}

TypeDBDriver* driver_open_for_tests(const char* address, const char* username, const char* password) {
DriverOptions* options = NULL;
Credentials* creds = credentials_new(username, password);
if (check_error_may_print(__FILE__, __LINE__)) goto cleanup;
options = driver_options_new(false, NULL);;
if (check_error_may_print(__FILE__, __LINE__)) goto cleanup;
TypeDBDriver* driver = driver_open_with_description(address, creds, options, DRIVER_LANG);
cleanup:
driver_options_drop(options);
credentials_drop(creds);

return driver;
}
6 changes: 5 additions & 1 deletion c/tests/integration/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
*/

extern const char* TYPEDB_CORE_ADDRESS;
extern const char* TYPEDB_CORE_USERNAME;
extern const char* TYPEDB_CORE_PASSWORD;

bool check_error_may_print(const char* filename, int lineno);

void delete_database_if_exists(DatabaseManager* databaseManager, const char* name);
TypeDBDriver* driver_open_for_tests(const char* address, const char* username, const char* password);

void delete_database_if_exists(TypeDBDriver* driver, const char* name);
Loading