-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollections.go
More file actions
56 lines (47 loc) · 1.61 KB
/
collections.go
File metadata and controls
56 lines (47 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* hlquery - Search beyond keywords.
* https://www.hlquery.com
*
* Copyright (C) 2021-2026, Carlos F. Ferry <carlos.ferry@gmail.com>
*
* This file is part of hlquery Go API client, released under the BSD License version 3.
*/
package hlquery
import "fmt"
// Collections provides collection management operations
type Collections struct {
client *Client
}
// List lists all collections
func (c *Collections) List(offset, limit int) (*Response, error) {
path := fmt.Sprintf("/collections?offset=%d&limit=%d", offset, limit)
return c.client.request("GET", path, nil)
}
// Get gets a collection by name
func (c *Collections) Get(name string) (*Response, error) {
return c.client.request("GET", "/collections/"+name, nil)
}
// Create creates a new collection
func (c *Collections) Create(name string, schema map[string]interface{}) (*Response, error) {
body := map[string]interface{}{
"name": name,
"fields": schema["fields"],
}
return c.client.request("POST", "/collections", body)
}
// Delete deletes a collection
func (c *Collections) Delete(name string) (*Response, error) {
return c.client.request("DELETE", "/collections/"+name, nil)
}
// Update updates a collection schema
func (c *Collections) Update(name string, schema map[string]interface{}) (*Response, error) {
body := map[string]interface{}{
"fields": schema["fields"],
}
return c.client.request("PUT", "/collections/"+name, body)
}
// GetFields gets formatted fields for a collection
func (c *Collections) GetFields(name string) (*Response, error) {
path := fmt.Sprintf("/collections/%s/fields", name)
return c.client.request("GET", path, nil)
}