Skip to content

Commit b45116c

Browse files
nickan2cfarost
andauthored
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]>
1 parent de01566 commit b45116c

30 files changed

+1246
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ See the table below for links to README files, documentation, and source code.
1919
| Java | [README](https://github.com/vaticle/typedb-driver/tree/development/java/README.md) | [Documentation](https://typedb.com/docs/drivers/java/overview) | [`java/`](https://github.com/vaticle/typedb-driver/tree/development/java) |
2020
| C | [README](https://github.com/vaticle/typedb-driver/tree/development/c/README.md) | See C++ | [`c/`](https://github.com/vaticle/typedb-driver/tree/development/c) |
2121
| C++ | [README](https://github.com/vaticle/typedb-driver/tree/development/cpp/README.md) | [Documentation](https://typedb.com/docs/drivers/cpp/overview) | [`cpp/`](https://github.com/vaticle/typedb-driver/tree/development/cpp) |
22-
| C# | [README](https://github.com/vaticle/typedb-driver/tree/development/csharp/README.md) | (Coming soon!) | [`csharp/`](https://github.com/vaticle/typedb-driver/tree/development/csharp) |
22+
| C# | [README](https://github.com/vaticle/typedb-driver/tree/development/csharp/README.md) | [Documentation](https://typedb.com/docs/drivers/csharp/overview) | [`csharp/`](https://github.com/vaticle/typedb-driver/tree/development/csharp) |
2323

2424
### Package hosting
2525

WORKSPACE

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ workspace(name = "vaticle_typedb_driver")
2020
##############################
2121
# Load @vaticle_dependencies #
2222
##############################
23-
2423
load("//dependencies/vaticle:repositories.bzl", "vaticle_dependencies")
2524
vaticle_dependencies()
2625

@@ -79,6 +78,22 @@ paket2bazel_dependencies()
7978
load("//csharp/nuget:paket.csharp_deps.bzl", csharp_deps = "csharp_deps")
8079
csharp_deps()
8180

81+
# Load //builder/go
82+
load("@vaticle_dependencies//builder/go:deps.bzl", go_deps = "deps")
83+
go_deps()
84+
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies")
85+
go_rules_dependencies()
86+
87+
load("//go:go_versions.bzl", "register_all_toolchains")
88+
register_all_toolchains()
89+
90+
# gazelle:repo bazel_gazelle <- Used to tell gazelle that it is loaded in a macro.
91+
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
92+
load("//go:deps.bzl", "go_repositories")
93+
# gazelle:repository_macro go/deps.bzl%go_repositories
94+
go_repositories()
95+
gazelle_dependencies()
96+
8297
# Load //builder/proto_grpc
8398
load("@vaticle_dependencies//builder/proto_grpc:deps.bzl", grpc_deps = "deps")
8499
grpc_deps()
@@ -246,6 +261,7 @@ vaticle_typedb_protocol_npm_repositories()
246261

247262
# Setup rules_ts
248263
load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")
264+
249265
rules_ts_dependencies(
250266
ts_version_from = "//nodejs:package.json",
251267
)

c/swig/typedb_driver_go.swg

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
/* TODO: Implement */

dependencies/vaticle/repositories.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def vaticle_dependencies():
2121
git_repository(
2222
name = "vaticle_dependencies",
2323
remote = "https://github.com/vaticle/dependencies",
24-
commit = "294ef724c3853c9851e1e0c6bc04e0470c724e10", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
24+
commit = "0b52d5d6dc5906d6a5dd6444ad2849466363ec6b", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
2525
)
2626

2727
def vaticle_typeql():

go/BUILD

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")
19+
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
20+
load("//go:rules.bzl", "swig_native_go_library")
21+
22+
# TODO: Building this target doesn't put the dynamic library (libtypedb_driver_go_native.dylib for MacOS) into
23+
# bazel-bin/go, while it's needed for the clinkopts below.
24+
swig_native_go_library(
25+
name = "typedb_driver_go_native",
26+
lib = "//c:typedb_driver_clib_headers",
27+
package_name= "typedb_driver",
28+
interface = "//c:typedb_driver.i",
29+
includes = ["//c:swig/typedb_driver_go.swg"],
30+
enable_cxx = True,
31+
visibility = ["//visibility:public"],
32+
)
33+
34+
# TODO: Cannot be built in CI because of the absolute path used in clinkopts.
35+
# For now, requires manually running `bazel build //go:libtypedb_driver_go_native` before this building this target.
36+
#go_library(
37+
# name = "driver-go",
38+
# srcs = glob(["*.go"]),
39+
# data = ["//:LICENSE"],
40+
# importpath = "typedb_driver/go",
41+
# clinkopts = [
42+
# "-L$TYPEDB_DRIVER_PATH/typedb-driver/bazel-bin/go", # TODO: Use relative path instead of the full path (couldn't make working for now)
43+
# "-ltypedb_driver_go_native",
44+
# "-framework", "CoreFoundation"
45+
# ],
46+
# deps = [
47+
# "//go:typedb_driver_go_native",
48+
# "//go/api/user:user",
49+
# "//go/api/database:database",
50+
# "//go/connection:connection",
51+
# ],
52+
# cgo = True,
53+
# visibility = ["//visibility:public"],
54+
#)
55+
56+
# TODO: The targets below are proofs of concept and are placed here for a simpler linker debug process.
57+
# It runs based on `driver_proof_of_concept.go` (NOTICE: this file is built inside the library, which is incorrect,
58+
# but it was enough for a simple proof of concept. Need to verify if the dynamic library can be found by external packages.
59+
#go_binary(
60+
# name = "driver-temp-exe",
61+
# embed = [":driver-go"],
62+
# visibility = ["//visibility:public"],
63+
#)
64+
65+
# TODO: This test doesn't work because it can't find the driver's native dynamic library.
66+
#go_test(
67+
# name = "db-connection-test",
68+
# srcs = ["//go/test/integration:db_connection_test.go"],
69+
# embed = ["//go:driver-go"],
70+
# visibility = ["//visibility:public"],
71+
#)
72+
73+
checkstyle_test(
74+
name = "checkstyle",
75+
size = "small",
76+
include = glob(["*"]),
77+
exclude = glob([
78+
"README.md",
79+
"docs/**/*.adoc",
80+
]),
81+
license_type = "apache-header",
82+
)

go/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# TypeDB Go Driver (WIP)
2+
3+
## Current state
4+
5+
`TypeDB Go Driver` is not implemented yet. This repository contains proofs of concept, including driver's library build
6+
phase and basic database manipulation functionality. A usage example could be found
7+
in [driver_proof_of_concept.go](driver_proof_of_concept.go) (database creation and deletion).
8+
9+
### Issues
10+
11+
- [BUILD](BUILD) expects manual actions to build on a specific machine and is not fully automated yet (more details
12+
below and inside the file)
13+
- Only basic connection and database manipulation features are implemented and not tested
14+
- There is no resource management, exceptions handling and some of the needed Rust structs wrappers on the SWIG side
15+
16+
### Run
17+
18+
- Run `bazel build //go:libtypedb_driver_go_native`
19+
- Uncomment `driver-go` (and `driver-temp-exe`) targets in [BUILD](BUILD)
20+
- Specify your local path to the `typedb_driver_go_native` dynamic library instead
21+
of `$TYPEDB_DRIVER_PATH/typedb-driver/bazel-bin/go`
22+
- Run `bazel build //go:driver-go` (or `bazel run //go:driver-temp-exe`). Make sure that you have a `TypeDB` server
23+
running to connect to it
24+
25+
```bash
26+
bazel build //go:libtypedb_driver_go_native
27+
bazel build //go:driver-go
28+
```

go/api/BUILD

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
package(default_visibility = ["//visibility:public"])
19+
20+
load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")
21+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
22+
23+
#go_library(
24+
# name = "api",
25+
# srcs = glob(["*.go", "*/*.go"]),
26+
# deps = [
27+
# "//go/api/database:database",
28+
# "//go/api/user:user",
29+
# "//go:typedb_driver_go_native",
30+
# ],
31+
# importpath = "typedb_driver/go/api",
32+
# visibility = ["//visibility:public"],
33+
# cgo = True
34+
#)
35+
36+
checkstyle_test(
37+
name = "checkstyle",
38+
include = glob(["*", "*/*"]),
39+
license_type = "apache-header",
40+
size = "small",
41+
)

go/api/TypeDBDriver.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package api
21+
22+
import (
23+
"typedb_driver/go/api/database"
24+
"typedb_driver/go/api/user"
25+
"typedb_driver/go_wrapper"
26+
)
27+
28+
type Driver interface {
29+
IsOpen() bool
30+
Databases() database.DatabaseManager
31+
Session() typedb_driver.Session // TODO: Implement sessions and return it instead of the native one
32+
Close()
33+
User() user.User
34+
Users() user.UserManager
35+
}

go/api/database/BUILD

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")
19+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
20+
21+
# TODO: Consider merging everything into api/BUILD
22+
#go_library(
23+
# name = "database",
24+
# srcs = [
25+
# "DatabaseManager.go",
26+
# "Database.go"
27+
# ],
28+
# importpath = "typedb_driver/go/api/database",
29+
# visibility = ["//visibility:public"],
30+
#)
31+
32+
checkstyle_test(
33+
name = "checkstyle",
34+
include = glob(["*"]),
35+
license_type = "apache-header",
36+
size = "small",
37+
)

go/api/database/Database.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package database
21+
22+
type Database interface {
23+
Name() string
24+
Schema() string
25+
TypeSchema() string
26+
RuleSchema() string
27+
Delete()
28+
Replicas() []Replica
29+
PrimaryReplica() Replica
30+
PreferredReplica() Replica
31+
}
32+
33+
type Replica interface {
34+
Server() string
35+
IsPrimary() bool
36+
IsPreferred() bool
37+
Term() int64
38+
}

0 commit comments

Comments
 (0)