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

🚀 Feature: add new function called findDocument() to find a document by query #57

Open
2 tasks done
bill-zhanxg opened this issue Jul 15, 2023 · 2 comments
Open
2 tasks done
Assignees
Labels
enhancement New feature or request

Comments

@bill-zhanxg
Copy link

🔖 Feature description

Add a new function in the Database SDK called findDocument which uses listDocument to get the first returned document with Query.

🎤 Pitch

This feature can be used if you have an id for attitude such as a user_id attribute and don't want it to be the same as the document id.

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@bill-zhanxg
Copy link
Author

bill-zhanxg commented Jul 15, 2023

maybe something like

     /**
     * List Documents
     * Get the first user's documents in a given collection using queries to filter your results.
     * @param databaseId
     * @param collectionId
     * @param queries
     * @throws — {AppwriteException}
     */
	findDocument<Document extends Models.Document>(
		databaseId: string,
		collectionId: string,
		queries: string[],
	): Promise<Document> {
		return new Promise((resolve, reject) => {
			this.listDocuments(databaseId, collectionId, queries)
				.then((document) => {
					if (document.documents[0]) resolve(document.documents[0]);
					else throw new AppwriteException('No document found');
				})
				.catch(reject);
		});
	}

@joeyouss joeyouss self-assigned this Jul 17, 2023
@joeyouss joeyouss added the enhancement New feature or request label Jul 17, 2023
@joeyouss
Copy link

Hi
As I can understand from this, you are looking to find a particular document in the list of documents. Currently, you can do this using loops and if you prefer changing the search parameters, you can use queries for you to filter, sort, and paginate results.

I will keep this issue open as of now since we are very keen in considering feedbacks from our community

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants