Skip to content

Commit

Permalink
Add queries field
Browse files Browse the repository at this point in the history
  • Loading branch information
melohagan committed Nov 24, 2023
1 parent 1893006 commit 230b883
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appwrite-databases",
"version": "1.2.3",
"version": "1.3.0",
"description": "Manage Databases, Collections, and Documents in Appwrite",
"main": "src/index.ts",
"license": "MIT",
Expand Down
7 changes: 6 additions & 1 deletion schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"datasource": {
"endpoint": {
"type": "string",
"required": true
"required": true,
"default": "https://cloud.appwrite.io/v1"
},
"projectId": {
"type": "string",
Expand Down Expand Up @@ -73,6 +74,10 @@
"documentId": {
"type": "string",
"required": false
},
"queries": {
"type": "string",
"required": false
}
}
},
Expand Down
16 changes: 12 additions & 4 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,31 @@ class CustomIntegration implements IntegrationBase {
return await this.databases.createDocument(query.databaseId, query.collectionId, query.documentId, query.data)
}

async read(query: { databaseId: string; collectionId: string; documentId: string; extra: { [key:string]: string; } }) {
async read(query: { databaseId: string; collectionId: string; documentId: string; queries: string; extra: { [key:string]: string; } }) {
let queries
if (query.queries) {
try {
queries = JSON.parse(query.queries)
} catch(e) {
throw "Invalid queries - must be a valid array."
}
}
if (query.extra.type === "Documents") {
if (query.documentId) {
return await this.databases.getDocument(query.databaseId, query.collectionId, query.documentId)
}
return await this.databases.listDocuments(query.databaseId, query.collectionId)
return await this.databases.listDocuments(query.databaseId, query.collectionId, queries)
}
if (query.extra.type === "Collections") {
if (query.collectionId) {
return await this.databases.getCollection(query.databaseId, query.collectionId)
}
return await this.databases.listCollections(query.databaseId)
return await this.databases.listCollections(query.databaseId, queries)
}
if (query.databaseId) {
return await this.databases.get(query.databaseId)
}
return await this.databases.list()
return await this.databases.list(queries)
}

async update(query: { databaseId: string; collectionId: string; name: string; extra: { [key:string]: string; } }) {
Expand Down

0 comments on commit 230b883

Please sign in to comment.