mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-19 08:50:46 +00:00
Added Collections CRUD
This commit is contained in:
50
internal/repositories/collections.go
Normal file
50
internal/repositories/collections.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package repositories
|
||||
|
||||
var collections = []Collection{
|
||||
{ID: "db1"},
|
||||
{ID: "db2"},
|
||||
}
|
||||
|
||||
func GetAllCollections(databaseId string) ([]Collection, RepositoryStatus) {
|
||||
var dbCollections []Collection
|
||||
|
||||
for _, coll := range collections {
|
||||
if coll.internals.databaseId == databaseId {
|
||||
dbCollections = append(dbCollections, coll)
|
||||
}
|
||||
}
|
||||
|
||||
return dbCollections, StatusOk
|
||||
}
|
||||
|
||||
func GetCollection(databaseId string, id string) (Collection, RepositoryStatus) {
|
||||
for _, coll := range collections {
|
||||
if coll.internals.databaseId == databaseId && coll.ID == id {
|
||||
return coll, StatusOk
|
||||
}
|
||||
}
|
||||
|
||||
return Collection{}, StatusNotFound
|
||||
}
|
||||
|
||||
func DeleteCollection(databaseId string, id string) RepositoryStatus {
|
||||
for index, coll := range collections {
|
||||
if coll.internals.databaseId == databaseId && coll.ID == id {
|
||||
collections = append(collections[:index], collections[index+1:]...)
|
||||
return StatusOk
|
||||
}
|
||||
}
|
||||
|
||||
return StatusNotFound
|
||||
}
|
||||
|
||||
func CreateCollection(databaseId string, newCollection Collection) RepositoryStatus {
|
||||
for _, coll := range collections {
|
||||
if coll.internals.databaseId == databaseId && coll.ID == newCollection.ID {
|
||||
return Conflict
|
||||
}
|
||||
}
|
||||
|
||||
collections = append(collections, newCollection)
|
||||
return StatusOk
|
||||
}
|
||||
@@ -11,3 +11,37 @@ const (
|
||||
StatusNotFound = 2
|
||||
Conflict = 3
|
||||
)
|
||||
|
||||
type Collection struct {
|
||||
ID string `json:"id"`
|
||||
IndexingPolicy struct {
|
||||
IndexingMode string `json:"indexingMode"`
|
||||
Automatic bool `json:"automatic"`
|
||||
IncludedPaths []struct {
|
||||
Path string `json:"path"`
|
||||
Indexes []struct {
|
||||
Kind string `json:"kind"`
|
||||
DataType string `json:"dataType"`
|
||||
Precision int `json:"precision"`
|
||||
} `json:"indexes"`
|
||||
} `json:"includedPaths"`
|
||||
ExcludedPaths []any `json:"excludedPaths"`
|
||||
} `json:"indexingPolicy"`
|
||||
PartitionKey struct {
|
||||
Paths []string `json:"paths"`
|
||||
Kind string `json:"kind"`
|
||||
Version int `json:"Version"`
|
||||
} `json:"partitionKey"`
|
||||
Rid string `json:"_rid"`
|
||||
Ts int `json:"_ts"`
|
||||
Self string `json:"_self"`
|
||||
Etag string `json:"_etag"`
|
||||
Docs string `json:"_docs"`
|
||||
Sprocs string `json:"_sprocs"`
|
||||
Triggers string `json:"_triggers"`
|
||||
Udfs string `json:"_udfs"`
|
||||
Conflicts string `json:"_conflicts"`
|
||||
internals struct {
|
||||
databaseId string
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user