Skip to content

Creating interface #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2017
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
8 changes: 8 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export GOBUILDDIR=$(pwd)/.gobuild
export GOPATH=$GOBUILDDIR:$GOPATH
PATH_add $GOBUILDDIR/bin

if [ ! -e ${GOBUILDDIR} ]; then
mkdir -p ${GOBUILDDIR}/src/github.com/arangodb/
ln -s ../../../.. ${GOBUILDDIR}/src/github.com/arangodb/go-driver
fi
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.gobuild
36 changes: 36 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Place your settings in this file to overwrite default and user settings.
{
"fileHeaderComment.parameter":{
"*":{
"commentprefix": "//",
"company": "ArangoDB GmbH, Cologne, Germany",
"author": "Ewout Prangsma"
}
},
"fileHeaderComment.template":{
"*":[
"${commentprefix} ",
"${commentprefix} DISCLAIMER",
"${commentprefix} ",
"${commentprefix} Copyright ${year} ArangoDB GmbH, Cologne, Germany",
"${commentprefix} ",
"${commentprefix} Licensed under the Apache License, Version 2.0 (the \"License\");",
"${commentprefix} you may not use this file except in compliance with the License.",
"${commentprefix} You may obtain a copy of the License at",
"${commentprefix} ",
"${commentprefix} http://www.apache.org/licenses/LICENSE-2.0",
"${commentprefix} ",
"${commentprefix} Unless required by applicable law or agreed to in writing, software",
"${commentprefix} distributed under the License is distributed on an \"AS IS\" BASIS,",
"${commentprefix} WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.",
"${commentprefix} See the License for the specific language governing permissions and",
"${commentprefix} limitations under the License.",
"${commentprefix} ",
"${commentprefix} Copyright holder is ArangoDB GmbH, Cologne, Germany",
"${commentprefix} ",
"${commentprefix} Author ${author}",
"${commentprefix} ",
""
]
}
}
52 changes: 52 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// DISCLAIMER
//
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
//
// Licensed 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Ewout Prangsma
//

package driver

import "context"

// Client provides access to a single arangodb database server, or an entire cluster of arangodb servers.
type Client interface {
// Database opens a connection to an existing database.
// If no database with given name exists, an NotFoundError is returned.
Database(ctx context.Context, name string) (Database, error)

// DatabaseExists returns true if a database with given name exists.
DatabaseExists(ctx context.Context, name string) (bool, error)

// Databases returns a list of all databases found by the client.
Databases(ctx context.Context) ([]Database, error)

// AccessibleDatabases returns a list of all databases that can be accessed by the authenticated user.
AccessibleDatabases(ctx context.Context) ([]Database, error)

// CreateDatabase creates a new database with given name and opens a connection to it.
// If the a database with given name already exists, a DuplicateError is returned.
CreateDatabase(ctx context.Context, name string) (Database, error)
}

// ClientConfig contains all settings needed to create a client.
type ClientConfig struct {
// Endpoints holds 1 or more URL's used to connect to the database.
// In case of a connection to an ArangoDB cluster, you must provide the URL's of all coordinators.
Endpoints []string
}
41 changes: 41 additions & 0 deletions collection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// DISCLAIMER
//
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
//
// Licensed 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Ewout Prangsma
//

package driver

import "context"

// Collection provides access to the documents in a single collection.
type Collection interface {
// Name returns the name of the collection.
Name() string

// ReadDocument reads a single document with given key from the collection.
// The document data is stored into result, the document meta data is returned.
// If no document exists with given key, a NotFoundError is returned.
ReadDocument(ctx context.Context, key string, result interface{}) (DocumentMeta, error)

// UpdateDocument updates a single document with given key in the collection.
// The document data is stored into result, the document meta data is returned.
// If no document exists with given key, a NotFoundError is returned.
UpdateDocument(ctx context.Context, key string, update map[string]interface{}, resultOld, resultNew interface{}) (DocumentMeta, error)
}
46 changes: 46 additions & 0 deletions database.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// DISCLAIMER
//
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
//
// Licensed 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Ewout Prangsma
//

package driver

import "context"

// Database provides access to all collections & graphs in a single database.
type Database interface {
// Collection opens a connection to an existing collection within the database.
// If no collection with given name exists, an NotFoundError is returned.
Collection(ctx context.Context, name string) (Collection, error)

// CollectionExists returns true if a collection with given name exists within the database.
CollectionExists(ctx context.Context, name string) (bool, error)

// Collections returns a list of all collections in the database.
Collections(ctx context.Context) ([]Collection, error)

// CreateCollection creates a new collection with given name and options, and opens a connection to it.
// If a collection with given name already exists within the database, a DuplicateError is returned.
CreateCollection(ctx context.Context, name string, options *CreateCollectionOptions) (Collection, error)
}

// CreateCollectionOptions contains options that customize the creating of a collection.
type CreateCollectionOptions struct {
}
52 changes: 52 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// DISCLAIMER
//
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
//
// Licensed 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Ewout Prangsma
//

package driver

// ArangoError is a Go error with arangodb specific error information.
type ArangoError struct {
HasError bool `json:"error"`
Code int `json:"code"`
ErrorNum int `json:"errorNum"`
ErrorMessage string `json:"errorMessage"`
}

// Error returns the error message of an ArangoError.
func (ae ArangoError) Error() string {
return ae.ErrorMessage
}

// IsArangoErrorWithCode returns true when the given error is an ArangoError and its Code field is equal to the given code.
func IsArangoErrorWithCode(err error, code int) bool {
ae, ok := err.(ArangoError)
return ok && ae.Code == code
}

// IsInvalidRequest return true if the given error is an ArangoError with code 400, indicating an invalid request.
func IsInvalidRequest(err error) bool {
return IsArangoErrorWithCode(err, 400)
}

// IsNotFound return true if the given error is an ArangoError with code 404, indicating a object not found.
func IsNotFound(err error) bool {
return IsArangoErrorWithCode(err, 404)
}
30 changes: 30 additions & 0 deletions meta.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// DISCLAIMER
//
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
//
// Licensed 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Ewout Prangsma
//

package driver

// DocumentMeta contains all meta data used to identifier a document.
type DocumentMeta struct {
Key string `json:"_key,omitempty"`
ID string `json:"_id,omitempty"`
Rev string `json:"_rev,omitempty"`
}