Skip to content

Commit

Permalink
Merge branch 'main' into issue-2760-rename-collection
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi authored Sep 8, 2023
2 parents 83bf069 + b032cd7 commit cf87825
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
5 changes: 2 additions & 3 deletions integration/commands_administration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,9 @@ func TestCommandsAdministrationCreateDropListDatabases(t *testing.T) {
assert.Equal(t, bson.D{{"ok", 1.0}}, res)
}

func TestCommandsAdministrationListDatabases(tt *testing.T) {
tt.Parallel()
func TestCommandsAdministrationListDatabases(t *testing.T) {
t.Parallel()

t := setup.FailsForSQLite(tt, "https://github.com/FerretDB/FerretDB/issues/3260")
ctx, collection := setup.Setup(t, shareddata.DocumentsStrings)

db := collection.Database()
Expand Down
23 changes: 21 additions & 2 deletions internal/backends/sqlite/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,27 @@ func (b *backend) ListDatabases(ctx context.Context, params *backends.ListDataba
res := &backends.ListDatabasesResult{
Databases: make([]backends.DatabaseInfo, len(list)),
}
for i, db := range list {
res.Databases[i] = backends.DatabaseInfo{Name: db}

for i, dbName := range list {
db, err := b.Database(dbName)
if err != nil {
return nil, lazyerrors.Error(err)
}

stats, err := db.Stats(ctx, new(backends.DatabaseStatsParams))
if backends.ErrorCodeIs(err, backends.ErrorCodeDatabaseDoesNotExist) {
stats = new(backends.DatabaseStatsResult)
err = nil
}

if err != nil {
return nil, lazyerrors.Error(err)
}

res.Databases[i] = backends.DatabaseInfo{
Name: dbName,
Size: stats.SizeTotal,
}
}

return res, nil
Expand Down

0 comments on commit cf87825

Please sign in to comment.