Added Collections CRUD

This commit is contained in:
Pijus Kamandulis
2024-02-10 18:52:41 +02:00
parent f30d0528bc
commit 5dc7d87fba
5 changed files with 179 additions and 5 deletions

View 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
}

View File

@@ -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
}
}