Skip to content

Commit 2a3bc2b

Browse files
fix: add query builder
1 parent f441bff commit 2a3bc2b

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { Appwrite } from "appwrite";
3333
To install with a CDN (content delivery network) add the following scripts to the bottom of your <body> tag, but before you use any Appwrite services:
3434

3535
```html
36-
<script src="https://cdn.jsdelivr.net/npm/appwrite@6.0.0"></script>
36+
<script src="https://cdn.jsdelivr.net/npm/appwrite@6.0.1"></script>
3737
```
3838

3939

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "appwrite",
33
"homepage": "https://appwrite.io/support",
44
"description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API",
5-
"version": "6.0.0",
5+
"version": "6.0.1",
66
"license": "BSD-3-Clause",
77
"main": "dist/cjs/sdk.js",
88
"exports": {

src/sdk.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ class Appwrite {
791791
locale: '',
792792
};
793793
headers: Headers = {
794-
'x-sdk-version': 'appwrite:web:6.0.0',
794+
'x-sdk-version': 'appwrite:web:6.0.1',
795795
'X-Appwrite-Response-Format': '0.12.0',
796796
};
797797

@@ -3504,5 +3504,44 @@ class Appwrite {
35043504

35053505
};
35063506

3507-
export { Appwrite }
3508-
export type { AppwriteException, Models }
3507+
type QueryTypesSingle = string | number | boolean;
3508+
type QueryTypesList = string[] | number[] | boolean[];
3509+
type QueryTypes = QueryTypesSingle | QueryTypesList;
3510+
3511+
class Query {
3512+
static equal = (attribute: string, value: QueryTypes): string =>
3513+
Query.addQuery(attribute, "equal", value);
3514+
3515+
static notEqual = (attribute: string, value: QueryTypes): string =>
3516+
Query.addQuery(attribute, "notEqual", value);
3517+
3518+
static lesser = (attribute: string, value: QueryTypes): string =>
3519+
Query.addQuery(attribute, "lesser", value);
3520+
3521+
static lesserEqual = (attribute: string, value: QueryTypes): string =>
3522+
Query.addQuery(attribute, "lesserEqual", value);
3523+
3524+
static greater = (attribute: string, value: QueryTypes): string =>
3525+
Query.addQuery(attribute, "greater", value);
3526+
3527+
static greaterEqual = (attribute: string, value: QueryTypes): string =>
3528+
Query.addQuery(attribute, "greaterEqual", value);
3529+
3530+
static search = (attribute: string, value: string): string =>
3531+
Query.addQuery(attribute, "search", value);
3532+
3533+
private static addQuery = (attribute: string, oper: string, value: QueryTypes): string =>
3534+
value instanceof Array
3535+
? `${attribute}.${oper}(${value
3536+
.map((v: QueryTypesSingle) => Query.parseValues(v))
3537+
.join(",")})`
3538+
: `${attribute}.${oper}(${Query.parseValues(value)})`;
3539+
3540+
private static parseValues = (value: QueryTypes): string =>
3541+
typeof value === "string" || value instanceof String
3542+
? `"${value}"`
3543+
: `${value}`;
3544+
}
3545+
3546+
export { Appwrite, Query }
3547+
export type { AppwriteException, Models, QueryTypes, QueryTypesList }

0 commit comments

Comments
 (0)