Add different data providers and improve docs

This adds support for switching between in-memory, local filesystem, s3
or sqlite.
This commit is contained in:
patwie
2024-03-29 10:02:31 +00:00
parent 2dd1421b6e
commit 31c8029402
10 changed files with 426 additions and 89 deletions
+31
View File
@@ -0,0 +1,31 @@
package memory
import (
"context"
"excalidraw-complete/core"
"fmt"
"github.com/oklog/ulid/v2"
)
var savedDocuments = make(map[string]core.Document)
type documentStore struct {
}
func NewDocumentStore() core.DocumentStore {
return &documentStore{}
}
func (s *documentStore) FindID(ctx context.Context, id string) (*core.Document, error) {
if val, ok := savedDocuments[id]; ok {
return &val, nil
}
return nil, fmt.Errorf("document with id %s not found", id)
}
func (s *documentStore) Create(ctx context.Context, document *core.Document) (string, error) {
id := ulid.Make().String()
savedDocuments[id] = *document
return id, nil
}