-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partial go driver implementation (#663)
## Usage and product changes Implement Basic core driver functionality of creating and closing a database. ## Implementation Implement User and Database interfaces, and Driver. Left a few TODO comments, for user functions, session functions and some iterator work where we need to use swig commands. --------- Co-authored-by: Georgii Novoselov <[email protected]>
- Loading branch information
Showing
30 changed files
with
1,246 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/* TODO: Implement */ |
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test") | ||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test") | ||
load("//go:rules.bzl", "swig_native_go_library") | ||
|
||
# TODO: Building this target doesn't put the dynamic library (libtypedb_driver_go_native.dylib for MacOS) into | ||
# bazel-bin/go, while it's needed for the clinkopts below. | ||
swig_native_go_library( | ||
name = "typedb_driver_go_native", | ||
lib = "//c:typedb_driver_clib_headers", | ||
package_name= "typedb_driver", | ||
interface = "//c:typedb_driver.i", | ||
includes = ["//c:swig/typedb_driver_go.swg"], | ||
enable_cxx = True, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
# TODO: Cannot be built in CI because of the absolute path used in clinkopts. | ||
# For now, requires manually running `bazel build //go:libtypedb_driver_go_native` before this building this target. | ||
#go_library( | ||
# name = "driver-go", | ||
# srcs = glob(["*.go"]), | ||
# data = ["//:LICENSE"], | ||
# importpath = "typedb_driver/go", | ||
# clinkopts = [ | ||
# "-L$TYPEDB_DRIVER_PATH/typedb-driver/bazel-bin/go", # TODO: Use relative path instead of the full path (couldn't make working for now) | ||
# "-ltypedb_driver_go_native", | ||
# "-framework", "CoreFoundation" | ||
# ], | ||
# deps = [ | ||
# "//go:typedb_driver_go_native", | ||
# "//go/api/user:user", | ||
# "//go/api/database:database", | ||
# "//go/connection:connection", | ||
# ], | ||
# cgo = True, | ||
# visibility = ["//visibility:public"], | ||
#) | ||
|
||
# TODO: The targets below are proofs of concept and are placed here for a simpler linker debug process. | ||
# It runs based on `driver_proof_of_concept.go` (NOTICE: this file is built inside the library, which is incorrect, | ||
# but it was enough for a simple proof of concept. Need to verify if the dynamic library can be found by external packages. | ||
#go_binary( | ||
# name = "driver-temp-exe", | ||
# embed = [":driver-go"], | ||
# visibility = ["//visibility:public"], | ||
#) | ||
|
||
# TODO: This test doesn't work because it can't find the driver's native dynamic library. | ||
#go_test( | ||
# name = "db-connection-test", | ||
# srcs = ["//go/test/integration:db_connection_test.go"], | ||
# embed = ["//go:driver-go"], | ||
# visibility = ["//visibility:public"], | ||
#) | ||
|
||
checkstyle_test( | ||
name = "checkstyle", | ||
size = "small", | ||
include = glob(["*"]), | ||
exclude = glob([ | ||
"README.md", | ||
"docs/**/*.adoc", | ||
]), | ||
license_type = "apache-header", | ||
) |
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,28 @@ | ||
# TypeDB Go Driver (WIP) | ||
|
||
## Current state | ||
|
||
`TypeDB Go Driver` is not implemented yet. This repository contains proofs of concept, including driver's library build | ||
phase and basic database manipulation functionality. A usage example could be found | ||
in [driver_proof_of_concept.go](driver_proof_of_concept.go) (database creation and deletion). | ||
|
||
### Issues | ||
|
||
- [BUILD](BUILD) expects manual actions to build on a specific machine and is not fully automated yet (more details | ||
below and inside the file) | ||
- Only basic connection and database manipulation features are implemented and not tested | ||
- There is no resource management, exceptions handling and some of the needed Rust structs wrappers on the SWIG side | ||
|
||
### Run | ||
|
||
- Run `bazel build //go:libtypedb_driver_go_native` | ||
- Uncomment `driver-go` (and `driver-temp-exe`) targets in [BUILD](BUILD) | ||
- Specify your local path to the `typedb_driver_go_native` dynamic library instead | ||
of `$TYPEDB_DRIVER_PATH/typedb-driver/bazel-bin/go` | ||
- Run `bazel build //go:driver-go` (or `bazel run //go:driver-temp-exe`). Make sure that you have a `TypeDB` server | ||
running to connect to it | ||
|
||
```bash | ||
bazel build //go:libtypedb_driver_go_native | ||
bazel build //go:driver-go | ||
``` |
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,41 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test") | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
#go_library( | ||
# name = "api", | ||
# srcs = glob(["*.go", "*/*.go"]), | ||
# deps = [ | ||
# "//go/api/database:database", | ||
# "//go/api/user:user", | ||
# "//go:typedb_driver_go_native", | ||
# ], | ||
# importpath = "typedb_driver/go/api", | ||
# visibility = ["//visibility:public"], | ||
# cgo = True | ||
#) | ||
|
||
checkstyle_test( | ||
name = "checkstyle", | ||
include = glob(["*", "*/*"]), | ||
license_type = "apache-header", | ||
size = "small", | ||
) |
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,35 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package api | ||
|
||
import ( | ||
"typedb_driver/go/api/database" | ||
"typedb_driver/go/api/user" | ||
"typedb_driver/go_wrapper" | ||
) | ||
|
||
type Driver interface { | ||
IsOpen() bool | ||
Databases() database.DatabaseManager | ||
Session() typedb_driver.Session // TODO: Implement sessions and return it instead of the native one | ||
Close() | ||
User() user.User | ||
Users() user.UserManager | ||
} |
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,37 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test") | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
# TODO: Consider merging everything into api/BUILD | ||
#go_library( | ||
# name = "database", | ||
# srcs = [ | ||
# "DatabaseManager.go", | ||
# "Database.go" | ||
# ], | ||
# importpath = "typedb_driver/go/api/database", | ||
# visibility = ["//visibility:public"], | ||
#) | ||
|
||
checkstyle_test( | ||
name = "checkstyle", | ||
include = glob(["*"]), | ||
license_type = "apache-header", | ||
size = "small", | ||
) |
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,38 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package database | ||
|
||
type Database interface { | ||
Name() string | ||
Schema() string | ||
TypeSchema() string | ||
RuleSchema() string | ||
Delete() | ||
Replicas() []Replica | ||
PrimaryReplica() Replica | ||
PreferredReplica() Replica | ||
} | ||
|
||
type Replica interface { | ||
Server() string | ||
IsPrimary() bool | ||
IsPreferred() bool | ||
Term() int64 | ||
} |
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,27 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package database | ||
|
||
type DatabaseManager interface { | ||
Get(name string) Database | ||
Contains(name string) bool | ||
Create(name string) | ||
All() []Database | ||
} |
Oops, something went wrong.