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

docstore/gcpfilestore: add support for non-default databases. #3345

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion docstore/gcpfirestore/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@
return fmt.Sprintf("projects/%s/databases/(default)/documents/%s", projectID, collPath)
}

// CollectResoureceIDWithDatabase constructs a resource ID for a collection from the project ID, database ID, and the collection path.
// See the OpenCollection example for use.
func CollectionResourceIDWithDatabase(projectID, databaseID, collPath string) string {
coryschwartz marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Sprintf("projects/%s/databases/%s/documents/%s", projectID, databaseID, collPath)

Check warning on line 155 in docstore/gcpfirestore/fs.go

View check run for this annotation

Codecov / codecov/patch

docstore/gcpfirestore/fs.go#L154-L155

Added lines #L154 - L155 were not covered by tests
}

// OpenCollection creates a *docstore.Collection representing a Firestore collection.
//
// collResourceID must be of the form "project/<projectID>/databases/(default)/documents/<collPath>".
Expand Down Expand Up @@ -193,7 +199,7 @@
return docstore.NewCollection(c), nil
}

var resourceIDRE = regexp.MustCompile(`^(projects/[^/]+/databases/\(default\))/documents/.+`)
var resourceIDRE = regexp.MustCompile(`^(projects/[^/]+/databases/[^/]+)/documents/.+`)

func newCollection(client *vkit.Client, collResourceID, nameField string, nameFunc func(docstore.Document) string, opts *Options) (*collection, error) {
if nameField == "" && nameFunc == nil {
Expand Down
2 changes: 1 addition & 1 deletion docstore/gcpfirestore/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func TestResourceIDRegexp(t *testing.T) {
for _, good := range []string{
"projects/abc-_.309/databases/(default)/documents/C",
"projects/P/databases/(default)/documents/C/D/E",
"projects/P/databases/mydb/documents/E/F/G",
} {
if !resourceIDRE.MatchString(good) {
t.Errorf("%q did not match but should have", good)
Expand All @@ -194,7 +195,6 @@ func TestResourceIDRegexp(t *testing.T) {
"Projects/P/databases/(default)/documents/C",
"P/databases/(default)/documents/C",
"projects/P/Q/databases/(default)/documents/C",
"projects/P/databases/mydb/documents/C",
"projects/P/databases/(default)/C",
"projects/P/databases/(default)/documents/",
"projects/P/databases/(default)",
Expand Down
Loading