Skip to content

Commit 3867c24

Browse files
[V2] Add views, analyzers and some _admin methods support, adjust collection props (#531)
1 parent 2c8aa41 commit 3867c24

35 files changed

+3432
-51
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
- [V2] Async Client
1111
- [V2] Fix connection.NewRequestWithEndpoint()
1212
- [V2] Add support for MaglevHashEndpoints
13+
- [V2] Add basic support for Views and Analyzers
14+
- [V2] Add ServerMode/SetServerMode/ServerID
15+
- [V2] Add collection Truncate, Count, Properties, SetProperties
16+
- [V2] Add and re-organize missing collection properties fields
1317

1418
## [1.6.0](https://github.com/arangodb/go-driver/tree/v1.6.0) (2023-05-30)
1519
- Add ErrArangoDatabaseNotFound and IsExternalStorageError helper to v2

HEADER

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
DISCLAIMER
33

4-
Copyright 2020 ArangoDB GmbH, Cologne, Germany
4+
Copyright 2023 ArangoDB GmbH, Cologne, Germany
55

66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.

v2/arangodb/analyzer.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// 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, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package arangodb
22+
23+
import "context"
24+
25+
type Analyzer interface {
26+
Name() string
27+
Database() Database
28+
29+
// Type returns the analyzer type
30+
Type() ArangoSearchAnalyzerType
31+
32+
// UniqueName returns the unique name: <database>::<analyzer-name>
33+
UniqueName() string
34+
35+
// Definition returns the analyzer definition
36+
Definition() AnalyzerDefinition
37+
38+
// Remove the analyzer
39+
Remove(ctx context.Context, force bool) error
40+
}
41+
42+
type AnalyzerDefinition struct {
43+
Name string `json:"name,omitempty"`
44+
Type ArangoSearchAnalyzerType `json:"type,omitempty"`
45+
Properties ArangoSearchAnalyzerProperties `json:"properties,omitempty"`
46+
Features []ArangoSearchFeature `json:"features,omitempty"`
47+
}

v2/arangodb/analyzer_impl.go

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// 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, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
20+
package arangodb
21+
22+
import (
23+
"context"
24+
"net/http"
25+
"strings"
26+
27+
"github.com/pkg/errors"
28+
29+
"github.com/arangodb/go-driver/v2/arangodb/shared"
30+
"github.com/arangodb/go-driver/v2/connection"
31+
)
32+
33+
func newAnalyzer(db *database, def AnalyzerDefinition, modifiers ...connection.RequestModifier) *analyzer {
34+
d := &analyzer{db: db, definition: def, modifiers: append(db.modifiers, modifiers...)}
35+
36+
return d
37+
}
38+
39+
var _ Analyzer = &analyzer{}
40+
41+
type analyzer struct {
42+
db *database
43+
44+
definition AnalyzerDefinition
45+
46+
modifiers []connection.RequestModifier
47+
}
48+
49+
func (a analyzer) Name() string {
50+
split := strings.Split(a.definition.Name, "::")
51+
return split[len(split)-1]
52+
}
53+
54+
func (a analyzer) UniqueName() string {
55+
return a.definition.Name
56+
}
57+
58+
func (a analyzer) Type() ArangoSearchAnalyzerType {
59+
return a.definition.Type
60+
}
61+
62+
func (a analyzer) Definition() AnalyzerDefinition {
63+
return a.definition
64+
}
65+
66+
func (v analyzer) Database() Database {
67+
return v.db
68+
}
69+
70+
func (v analyzer) Remove(ctx context.Context, force bool) error {
71+
url := v.db.url("_api", "analyzer", v.Name())
72+
73+
reqBody := struct {
74+
Force bool `json:"force,omitempty"`
75+
}{
76+
Force: force,
77+
}
78+
var response struct {
79+
shared.ResponseStruct `json:",inline"`
80+
}
81+
resp, err := connection.CallDelete(ctx, v.db.connection(), url, &response, connection.WithBody(reqBody))
82+
if err != nil {
83+
return errors.WithStack(err)
84+
}
85+
86+
switch code := resp.Code(); code {
87+
case http.StatusOK:
88+
return nil
89+
default:
90+
return response.AsArangoErrorWithCode(code)
91+
}
92+
}

0 commit comments

Comments
 (0)