mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-19 17:00:37 +00:00
Rename 'MapDS' to 'JsonDS'; Added some docs
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package mapdatastore
|
||||
package jsondatastore
|
||||
|
||||
import "github.com/pikami/cosmium/internal/datastore"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package mapdatastore
|
||||
package jsondatastore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
func (r *MapDataStore) GetAllCollections(databaseId string) ([]datastore.Collection, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) GetAllCollections(databaseId string) ([]datastore.Collection, datastore.DataStoreStatus) {
|
||||
r.storeState.RLock()
|
||||
defer r.storeState.RUnlock()
|
||||
|
||||
@@ -22,7 +22,7 @@ func (r *MapDataStore) GetAllCollections(databaseId string) ([]datastore.Collect
|
||||
return maps.Values(r.storeState.Collections[databaseId]), datastore.StatusOk
|
||||
}
|
||||
|
||||
func (r *MapDataStore) GetCollection(databaseId string, collectionId string) (datastore.Collection, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) GetCollection(databaseId string, collectionId string) (datastore.Collection, datastore.DataStoreStatus) {
|
||||
r.storeState.RLock()
|
||||
defer r.storeState.RUnlock()
|
||||
|
||||
@@ -37,7 +37,7 @@ func (r *MapDataStore) GetCollection(databaseId string, collectionId string) (da
|
||||
return r.storeState.Collections[databaseId][collectionId], datastore.StatusOk
|
||||
}
|
||||
|
||||
func (r *MapDataStore) DeleteCollection(databaseId string, collectionId string) datastore.DataStoreStatus {
|
||||
func (r *JsonDataStore) DeleteCollection(databaseId string, collectionId string) datastore.DataStoreStatus {
|
||||
r.storeState.Lock()
|
||||
defer r.storeState.Unlock()
|
||||
|
||||
@@ -58,7 +58,7 @@ func (r *MapDataStore) DeleteCollection(databaseId string, collectionId string)
|
||||
return datastore.StatusOk
|
||||
}
|
||||
|
||||
func (r *MapDataStore) CreateCollection(databaseId string, newCollection datastore.Collection) (datastore.Collection, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) CreateCollection(databaseId string, newCollection datastore.Collection) (datastore.Collection, datastore.DataStoreStatus) {
|
||||
r.storeState.Lock()
|
||||
defer r.storeState.Unlock()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package mapdatastore
|
||||
package jsondatastore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -10,14 +10,14 @@ import (
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
func (r *MapDataStore) GetAllDatabases() ([]datastore.Database, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) GetAllDatabases() ([]datastore.Database, datastore.DataStoreStatus) {
|
||||
r.storeState.RLock()
|
||||
defer r.storeState.RUnlock()
|
||||
|
||||
return maps.Values(r.storeState.Databases), datastore.StatusOk
|
||||
}
|
||||
|
||||
func (r *MapDataStore) GetDatabase(id string) (datastore.Database, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) GetDatabase(id string) (datastore.Database, datastore.DataStoreStatus) {
|
||||
r.storeState.RLock()
|
||||
defer r.storeState.RUnlock()
|
||||
|
||||
@@ -28,7 +28,7 @@ func (r *MapDataStore) GetDatabase(id string) (datastore.Database, datastore.Dat
|
||||
return datastore.Database{}, datastore.StatusNotFound
|
||||
}
|
||||
|
||||
func (r *MapDataStore) DeleteDatabase(id string) datastore.DataStoreStatus {
|
||||
func (r *JsonDataStore) DeleteDatabase(id string) datastore.DataStoreStatus {
|
||||
r.storeState.Lock()
|
||||
defer r.storeState.Unlock()
|
||||
|
||||
@@ -46,7 +46,7 @@ func (r *MapDataStore) DeleteDatabase(id string) datastore.DataStoreStatus {
|
||||
return datastore.StatusOk
|
||||
}
|
||||
|
||||
func (r *MapDataStore) CreateDatabase(newDatabase datastore.Database) (datastore.Database, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) CreateDatabase(newDatabase datastore.Database) (datastore.Database, datastore.DataStoreStatus) {
|
||||
r.storeState.Lock()
|
||||
defer r.storeState.Unlock()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package mapdatastore
|
||||
package jsondatastore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
func (r *MapDataStore) GetAllDocuments(databaseId string, collectionId string) ([]datastore.Document, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) GetAllDocuments(databaseId string, collectionId string) ([]datastore.Document, datastore.DataStoreStatus) {
|
||||
r.storeState.RLock()
|
||||
defer r.storeState.RUnlock()
|
||||
|
||||
@@ -25,7 +25,7 @@ func (r *MapDataStore) GetAllDocuments(databaseId string, collectionId string) (
|
||||
return maps.Values(r.storeState.Documents[databaseId][collectionId]), datastore.StatusOk
|
||||
}
|
||||
|
||||
func (r *MapDataStore) GetDocument(databaseId string, collectionId string, documentId string) (datastore.Document, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) GetDocument(databaseId string, collectionId string, documentId string) (datastore.Document, datastore.DataStoreStatus) {
|
||||
r.storeState.RLock()
|
||||
defer r.storeState.RUnlock()
|
||||
|
||||
@@ -44,7 +44,7 @@ func (r *MapDataStore) GetDocument(databaseId string, collectionId string, docum
|
||||
return r.storeState.Documents[databaseId][collectionId][documentId], datastore.StatusOk
|
||||
}
|
||||
|
||||
func (r *MapDataStore) DeleteDocument(databaseId string, collectionId string, documentId string) datastore.DataStoreStatus {
|
||||
func (r *JsonDataStore) DeleteDocument(databaseId string, collectionId string, documentId string) datastore.DataStoreStatus {
|
||||
r.storeState.Lock()
|
||||
defer r.storeState.Unlock()
|
||||
|
||||
@@ -65,7 +65,7 @@ func (r *MapDataStore) DeleteDocument(databaseId string, collectionId string, do
|
||||
return datastore.StatusOk
|
||||
}
|
||||
|
||||
func (r *MapDataStore) CreateDocument(databaseId string, collectionId string, document map[string]interface{}) (datastore.Document, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) CreateDocument(databaseId string, collectionId string, document map[string]interface{}) (datastore.Document, datastore.DataStoreStatus) {
|
||||
r.storeState.Lock()
|
||||
defer r.storeState.Unlock()
|
||||
|
||||
@@ -100,7 +100,7 @@ func (r *MapDataStore) CreateDocument(databaseId string, collectionId string, do
|
||||
return document, datastore.StatusOk
|
||||
}
|
||||
|
||||
func (r *MapDataStore) GetDocumentIterator(databaseId string, collectionId string) (datastore.DocumentIterator, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) GetDocumentIterator(databaseId string, collectionId string) (datastore.DocumentIterator, datastore.DataStoreStatus) {
|
||||
documents, status := r.GetAllDocuments(databaseId, collectionId)
|
||||
if status != datastore.StatusOk {
|
||||
return nil, status
|
||||
@@ -1,21 +1,21 @@
|
||||
package mapdatastore
|
||||
package jsondatastore
|
||||
|
||||
import "github.com/pikami/cosmium/internal/datastore"
|
||||
|
||||
type MapDataStore struct {
|
||||
type JsonDataStore struct {
|
||||
storeState State
|
||||
|
||||
initialDataFilePath string
|
||||
persistDataFilePath string
|
||||
}
|
||||
|
||||
type MapDataStoreOptions struct {
|
||||
type JsonDataStoreOptions struct {
|
||||
InitialDataFilePath string
|
||||
PersistDataFilePath string
|
||||
}
|
||||
|
||||
func NewMapDataStore(options MapDataStoreOptions) *MapDataStore {
|
||||
dataStore := &MapDataStore{
|
||||
func NewJsonDataStore(options JsonDataStoreOptions) *JsonDataStore {
|
||||
dataStore := &JsonDataStore{
|
||||
storeState: State{
|
||||
Databases: make(map[string]datastore.Database),
|
||||
Collections: make(map[string]map[string]datastore.Collection),
|
||||
@@ -1,4 +1,4 @@
|
||||
package mapdatastore
|
||||
package jsondatastore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
// I have no idea what this is tbh
|
||||
func (r *MapDataStore) GetPartitionKeyRanges(databaseId string, collectionId string) ([]datastore.PartitionKeyRange, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) GetPartitionKeyRanges(databaseId string, collectionId string) ([]datastore.PartitionKeyRange, datastore.DataStoreStatus) {
|
||||
r.storeState.RLock()
|
||||
defer r.storeState.RUnlock()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package mapdatastore
|
||||
package jsondatastore
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -33,7 +33,7 @@ type State struct {
|
||||
UserDefinedFunctions map[string]map[string]map[string]datastore.UserDefinedFunction `json:"udfs"`
|
||||
}
|
||||
|
||||
func (r *MapDataStore) InitializeDataStore() {
|
||||
func (r *JsonDataStore) InitializeDataStore() {
|
||||
if r.initialDataFilePath != "" {
|
||||
r.LoadStateFS(r.initialDataFilePath)
|
||||
return
|
||||
@@ -55,7 +55,7 @@ func (r *MapDataStore) InitializeDataStore() {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *MapDataStore) LoadStateFS(filePath string) {
|
||||
func (r *JsonDataStore) LoadStateFS(filePath string) {
|
||||
data, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error reading state JSON file: %v", err)
|
||||
@@ -68,7 +68,7 @@ func (r *MapDataStore) LoadStateFS(filePath string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *MapDataStore) LoadStateJSON(jsonData string) error {
|
||||
func (r *JsonDataStore) LoadStateJSON(jsonData string) error {
|
||||
r.storeState.Lock()
|
||||
defer r.storeState.Unlock()
|
||||
|
||||
@@ -94,7 +94,7 @@ func (r *MapDataStore) LoadStateJSON(jsonData string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *MapDataStore) SaveStateFS(filePath string) {
|
||||
func (r *JsonDataStore) SaveStateFS(filePath string) {
|
||||
r.storeState.RLock()
|
||||
defer r.storeState.RUnlock()
|
||||
|
||||
@@ -115,7 +115,7 @@ func (r *MapDataStore) SaveStateFS(filePath string) {
|
||||
logger.Infof("User defined functions: %d\n", getLength(r.storeState.UserDefinedFunctions))
|
||||
}
|
||||
|
||||
func (r *MapDataStore) DumpToJson() (string, error) {
|
||||
func (r *JsonDataStore) DumpToJson() (string, error) {
|
||||
r.storeState.RLock()
|
||||
defer r.storeState.RUnlock()
|
||||
|
||||
@@ -129,7 +129,7 @@ func (r *MapDataStore) DumpToJson() (string, error) {
|
||||
|
||||
}
|
||||
|
||||
func (r *MapDataStore) Close() {
|
||||
func (r *JsonDataStore) Close() {
|
||||
if r.persistDataFilePath != "" {
|
||||
r.SaveStateFS(r.persistDataFilePath)
|
||||
}
|
||||
@@ -163,7 +163,7 @@ func getLength(v interface{}) int {
|
||||
return count
|
||||
}
|
||||
|
||||
func (r *MapDataStore) ensureStoreStateNoNullReferences() {
|
||||
func (r *JsonDataStore) ensureStoreStateNoNullReferences() {
|
||||
if r.storeState.Databases == nil {
|
||||
r.storeState.Databases = make(map[string]datastore.Database)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package mapdatastore
|
||||
package jsondatastore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -10,14 +10,14 @@ import (
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
func (r *MapDataStore) GetAllStoredProcedures(databaseId string, collectionId string) ([]datastore.StoredProcedure, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) GetAllStoredProcedures(databaseId string, collectionId string) ([]datastore.StoredProcedure, datastore.DataStoreStatus) {
|
||||
r.storeState.RLock()
|
||||
defer r.storeState.RUnlock()
|
||||
|
||||
return maps.Values(r.storeState.StoredProcedures[databaseId][collectionId]), datastore.StatusOk
|
||||
}
|
||||
|
||||
func (r *MapDataStore) GetStoredProcedure(databaseId string, collectionId string, spId string) (datastore.StoredProcedure, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) GetStoredProcedure(databaseId string, collectionId string, spId string) (datastore.StoredProcedure, datastore.DataStoreStatus) {
|
||||
r.storeState.RLock()
|
||||
defer r.storeState.RUnlock()
|
||||
|
||||
@@ -36,7 +36,7 @@ func (r *MapDataStore) GetStoredProcedure(databaseId string, collectionId string
|
||||
return datastore.StoredProcedure{}, datastore.StatusNotFound
|
||||
}
|
||||
|
||||
func (r *MapDataStore) DeleteStoredProcedure(databaseId string, collectionId string, spId string) datastore.DataStoreStatus {
|
||||
func (r *JsonDataStore) DeleteStoredProcedure(databaseId string, collectionId string, spId string) datastore.DataStoreStatus {
|
||||
r.storeState.Lock()
|
||||
defer r.storeState.Unlock()
|
||||
|
||||
@@ -57,7 +57,7 @@ func (r *MapDataStore) DeleteStoredProcedure(databaseId string, collectionId str
|
||||
return datastore.StatusOk
|
||||
}
|
||||
|
||||
func (r *MapDataStore) CreateStoredProcedure(databaseId string, collectionId string, sp datastore.StoredProcedure) (datastore.StoredProcedure, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) CreateStoredProcedure(databaseId string, collectionId string, sp datastore.StoredProcedure) (datastore.StoredProcedure, datastore.DataStoreStatus) {
|
||||
r.storeState.Lock()
|
||||
defer r.storeState.Unlock()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package mapdatastore
|
||||
package jsondatastore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -10,14 +10,14 @@ import (
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
func (r *MapDataStore) GetAllTriggers(databaseId string, collectionId string) ([]datastore.Trigger, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) GetAllTriggers(databaseId string, collectionId string) ([]datastore.Trigger, datastore.DataStoreStatus) {
|
||||
r.storeState.RLock()
|
||||
defer r.storeState.RUnlock()
|
||||
|
||||
return maps.Values(r.storeState.Triggers[databaseId][collectionId]), datastore.StatusOk
|
||||
}
|
||||
|
||||
func (r *MapDataStore) GetTrigger(databaseId string, collectionId string, triggerId string) (datastore.Trigger, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) GetTrigger(databaseId string, collectionId string, triggerId string) (datastore.Trigger, datastore.DataStoreStatus) {
|
||||
r.storeState.RLock()
|
||||
defer r.storeState.RUnlock()
|
||||
|
||||
@@ -36,7 +36,7 @@ func (r *MapDataStore) GetTrigger(databaseId string, collectionId string, trigge
|
||||
return datastore.Trigger{}, datastore.StatusNotFound
|
||||
}
|
||||
|
||||
func (r *MapDataStore) DeleteTrigger(databaseId string, collectionId string, triggerId string) datastore.DataStoreStatus {
|
||||
func (r *JsonDataStore) DeleteTrigger(databaseId string, collectionId string, triggerId string) datastore.DataStoreStatus {
|
||||
r.storeState.Lock()
|
||||
defer r.storeState.Unlock()
|
||||
|
||||
@@ -57,7 +57,7 @@ func (r *MapDataStore) DeleteTrigger(databaseId string, collectionId string, tri
|
||||
return datastore.StatusOk
|
||||
}
|
||||
|
||||
func (r *MapDataStore) CreateTrigger(databaseId string, collectionId string, trigger datastore.Trigger) (datastore.Trigger, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) CreateTrigger(databaseId string, collectionId string, trigger datastore.Trigger) (datastore.Trigger, datastore.DataStoreStatus) {
|
||||
r.storeState.Lock()
|
||||
defer r.storeState.Unlock()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package mapdatastore
|
||||
package jsondatastore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -10,14 +10,14 @@ import (
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
func (r *MapDataStore) GetAllUserDefinedFunctions(databaseId string, collectionId string) ([]datastore.UserDefinedFunction, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) GetAllUserDefinedFunctions(databaseId string, collectionId string) ([]datastore.UserDefinedFunction, datastore.DataStoreStatus) {
|
||||
r.storeState.RLock()
|
||||
defer r.storeState.RUnlock()
|
||||
|
||||
return maps.Values(r.storeState.UserDefinedFunctions[databaseId][collectionId]), datastore.StatusOk
|
||||
}
|
||||
|
||||
func (r *MapDataStore) GetUserDefinedFunction(databaseId string, collectionId string, udfId string) (datastore.UserDefinedFunction, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) GetUserDefinedFunction(databaseId string, collectionId string, udfId string) (datastore.UserDefinedFunction, datastore.DataStoreStatus) {
|
||||
r.storeState.RLock()
|
||||
defer r.storeState.RUnlock()
|
||||
|
||||
@@ -36,7 +36,7 @@ func (r *MapDataStore) GetUserDefinedFunction(databaseId string, collectionId st
|
||||
return datastore.UserDefinedFunction{}, datastore.StatusNotFound
|
||||
}
|
||||
|
||||
func (r *MapDataStore) DeleteUserDefinedFunction(databaseId string, collectionId string, udfId string) datastore.DataStoreStatus {
|
||||
func (r *JsonDataStore) DeleteUserDefinedFunction(databaseId string, collectionId string, udfId string) datastore.DataStoreStatus {
|
||||
r.storeState.Lock()
|
||||
defer r.storeState.Unlock()
|
||||
|
||||
@@ -57,7 +57,7 @@ func (r *MapDataStore) DeleteUserDefinedFunction(databaseId string, collectionId
|
||||
return datastore.StatusOk
|
||||
}
|
||||
|
||||
func (r *MapDataStore) CreateUserDefinedFunction(databaseId string, collectionId string, udf datastore.UserDefinedFunction) (datastore.UserDefinedFunction, datastore.DataStoreStatus) {
|
||||
func (r *JsonDataStore) CreateUserDefinedFunction(databaseId string, collectionId string, udf datastore.UserDefinedFunction) (datastore.UserDefinedFunction, datastore.DataStoreStatus) {
|
||||
r.storeState.Lock()
|
||||
defer r.storeState.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user