Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement metadata storage #2656

Merged
merged 41 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
lint
  • Loading branch information
Dmitry committed May 18, 2023
commit c95ede7a09b5b51c0207f13c0694527934e4bb4e
2 changes: 1 addition & 1 deletion internal/backends/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ type InsertParams struct {

// InsertResult represents the results of Collection.Insert method.
type InsertResult struct {
InsertedCount int64
Errors *commonerrors.WriteErrors
AlekSi marked this conversation as resolved.
Show resolved Hide resolved
InsertedCount int64
}

// Insert inserts documents into the collection.
Expand Down
11 changes: 8 additions & 3 deletions internal/backends/sqlite/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/FerretDB/FerretDB/internal/backends"
"github.com/FerretDB/FerretDB/internal/handlers/commonerrors"
"github.com/FerretDB/FerretDB/internal/handlers/sjson"
"github.com/FerretDB/FerretDB/internal/types"
"github.com/FerretDB/FerretDB/internal/util/iterator"
)

Expand Down Expand Up @@ -66,7 +67,9 @@ func (c *collection) Insert(ctx context.Context, params *backends.InsertParams)
var inserted int64

for {
_, doc, err := params.Docs.Next()
var doc *types.Document

_, doc, err = params.Docs.Next()
if errors.Is(err, iterator.ErrIteratorDone) {
break
}
Expand All @@ -77,7 +80,9 @@ func (c *collection) Insert(ctx context.Context, params *backends.InsertParams)

query := fmt.Sprintf(`INSERT INTO %s (sjson) VALUES (?)`, table)

bytes, err := sjson.Marshal(doc)
var bytes []byte

bytes, err = sjson.Marshal(doc)
if err != nil {
return nil, err
}
Expand All @@ -99,7 +104,7 @@ func (c *collection) Insert(ctx context.Context, params *backends.InsertParams)

return &backends.InsertResult{
InsertedCount: inserted,
Errors: &commonerrors.WriteErrors{},
Errors: new(commonerrors.WriteErrors),
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/backends/sqlite/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (db *database) CreateCollection(ctx context.Context, params *backends.Creat
}

if !exists {
if err := db.create(ctx); err != nil {
if err = db.create(ctx); err != nil {
return lazyerrors.Error(err)
}
}
Expand Down Expand Up @@ -138,7 +138,7 @@ func (db *database) create(ctx context.Context) error {
return err
}

if err := f.Close(); err != nil {
if err = f.Close(); err != nil {
return err
}

Expand Down
1 change: 1 addition & 0 deletions internal/handlers/common/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func GetInsertParams(document *types.Document, l *zap.Logger) (*InsertParams, er
if params.Docs != nil {
for i := 0; i < params.Docs.Len(); i++ {
value := must.NotFail(params.Docs.Get(i))

doc, ok := value.(*types.Document)
if !ok {
return nil, lazyerrors.Errorf("expected document, got %v", value)
Expand Down