Easily generate queries for the Google Drive™ API.
npm install query-builder-for-driveapi
Before we start with the basic usage, let's look at all the classes and enums exported from this package.
import QueryBuilder, { // Class builder for generating queries
FileType, // Enum with basic file types (mime types)
VisibilityLevel // Enum with visibility levels
} from 'query-builder-for-driveapi'
// Create an instance of QueryBuilder
const qb = new QueryBuilder()
// Add inputs (queries) to the query builder
qb.collection({ parents: 'parent-id' })
qb.fileName('test.txt')
// Build the query into a string
const query = qb.build()
//=> 'parent-id' in parents and name = 'test.txt' and trashed = false
Important
To avoid "accidents", the build()
method adds a trashed = false
to the query by default.
Note: If you want to change this behavior in your query, simply call the trashed()
method before calling the build()
method.
Collection | Method |
---|---|
parents |
collection({
[K in Collection]?: string | string[]
}) |
owners | |
writers | |
readers |
Field | Operator (if applicable) | Method |
---|---|---|
name |
|
fileName(string | string[])
fileName({
[K in Operator]?: string | string[]
}) |
mimeType |
fileType(string | string[])
fileType({
[K in Operator]?: string | string[]
}) | |
fullText |
content(string | string[]) | |
properties |
property({
[K in string]: unknown | unknown[]
}) | |
appProperties |
appProperty({
[K in string]: unknown | unknown[]
}) | |
visibility |
|
visibility(string | string[])
visibility({
[K in Operator]?: string | string[]
}) |
shortcutDetails.targetId |
shortcutTargetId(string | string[])
shortcutTargetId({
[K in Operator]?: string | string[]
}) | |
orgUnitId |
orgDriveId(string | string[])
orgDriveId({
[K in Operator]?: string | string[]
}) | |
sharedWithMe |
shared(boolean?) // default: true | |
trashed |
trashed(boolean?) // default: true | |
starred |
starred(boolean?) // default: true | |
hidden |
hidden(boolean?) // default: true | |
createdTime |
|
createdAt(string | string[])
createdAt({
[K in Operator]?: string | string[]
}) |
modifiedTime |
updatedAt(string | string[])
updatedAt({
[K in Operator]?: string | string[]
}) | |
viewedByMeTime |
viewedAt(string | string[])
viewedAt({
[K in Operator]?: string | string[]
}) | |
organizerCount |
organizerCount(number | number[])
organizerCount({
[K in Operator]?: number | number[]
}) | |
memberCount |
memberCount(number | number[])
memberCount({
[K in Operator]?: number | number[]
}) |
Method | Sample |
---|---|
negate(() => void) |
const qb = new QueryBuilder()
// negates the queries in the callback
qb.negate(() => {
qb.fileName('test.txt')
qb.createdAt('2023-01-01')
})
qb.content('some content')
qb.build()
//=> not name = 'test.txt'
// and not createdTime = '2023-01-01'
// and fullText = 'some content'
// and trashed = false |
build() |
© 2023 Brian Fernandez
This project is licensed under the MIT license. See the file LICENSE for details.
No affiliation with Google Inc.
This package is a third-party offering and is not a product of Google Inc.
Google Drive™ is a trademark of Google Inc.