Easily generate queries for the Google Drive API.
npm install query-builder-for-driveapi
// Using ES6 Imports
import QueryBuilder, { Collection, FileType, VisibilityLevel } from 'query-builder-for-driveapi'
// Using CommonJS
const QueryBuilder = require('query-builder-for-driveapi')
const { Collection, FileType, VisibilityLevel } = QueryBuilder
// Create an instance
const qb = new QueryBuilder()
// Add inputs (queries)
qb.getByCollection(Collection.PARENTS, 'parent-id')
qb.getByFileName('something')
// Build inputs (queries) in a query
const query = qb.build()
//=> ('parent-id' in parents) and (name = 'something')
Create an instance of QueryBuilder.
new QueryBuilder()
From now on all the examples of each method will use an instance of QueryBuilder
associated to the constant qb
.
Indicates whether the collection contains the specified values.
Type: Collection
Collection.PARENTS
:
qb.getByCollection(Collection.PARENTS, ...).build()
//=> ('...' in parents)
Collection.OWNERS
:
qb.getByCollection(Collection.OWNERS, ...).build()
//=> ('...' in owners)
Collection.WRITERS
:
qb.getByCollection(Collection.WRITERS, ...).build()
//=> ('...' in writers)
Collection.READERS
:
qb.getByCollection(Collection.READERS, ...).build()
//=> ('...' in readers)
Type: string | string[]
qb.getByCollection(..., 'value').build()
//=> ('value' in ...)
qb.getByCollection(..., ['value-1', 'value-2']).build()
//=> ('value-1' in ... or 'value-2' in ...)
Indicates whether the file name is equal to the specified file name.
Type: string | string[]
qb.getByFileName('value').build()
//=> (name = 'value')
qb.getByFileName(['value-1', 'value-2']).build()
//=> (name = 'value-1' or name = 'value-2')
Indicates whether the file name, description, indexableText or content text properties or metadata of the file contains the specified value.
Type: string | string[]
qb.getByContent('value').build()
//=> (fullText = 'value')
qb.getByContent(['value-1', 'value-2']).build()
//=> (fullText = 'value-1' or fullText = 'value-2')
Indicates whether the MIME type of the file is equal to the specified file type.
Type: string | FileType | (string | FileType)[]
FileType.FOLDER
:
qb.getByFileType(FileType.FOLDER).build()
//=> (mimeType = 'application/vnd.google-apps.folder')
FileType.DOCUMENT
:
qb.getByFileType(FileType.DOCUMENT).build()
//=> (mimeType = 'application/vnd.google-apps.document')
FileType.SPREADSHEET
:
qb.getByFileType(FileType.SPREADSHEET).build()
//=> (mimeType = 'application/vnd.google-apps.spreadsheet')
FileType.PRESENTATION
:
qb.getByFileType(FileType.PRESENTATION).build()
//=> (mimeType = 'application/vnd.google-apps.presentation')
FileType.FORM
:
qb.getByFileType(FileType.FORM).build()
//=> (mimeType = 'application/vnd.google-apps.form')
Others
:
qb.getByFileType('image/jpeg').build()
//=> (mimeType = 'image/jpeg')
qb.getByFileType(['image/png', FileType.DOCUMENT]).build()
//=> (mimeType = 'image/png' or mimeType = 'application/vnd.google-apps.document')
Indicates whether the creation date of the file is equal to the specified timestamp.
Type: string | string[]
Uses RFC 3339 format, the default timezone is UTC, such as 2011-10-05T14:48:00Z.
qb.getByCreatedAt('2011-10-05T14:48:00Z').build()
//=> (createdTime = '2011-10-05T14:48:00Z')
qb.getByCreatedAt(['2019-09-07T15:50Z', '2012-06-04T12:00:00Z']).build()
//=> (createdTime = '2019-09-07T15:50Z' or createdTime = '2012-06-04T12:00:00Z')
Indicates whether the modified date of the file is equal to the specified timestamp.
Type: string | string[]
Uses RFC 3339 format, the default timezone is UTC, such as 2011-10-05T14:48:00Z.
qb.getByUpdatedAt('2011-10-05T14:48:00Z').build()
//=> (modifiedTime = '2011-10-05T14:48:00Z')
qb.getByUpdatedAt(['2019-09-07T15:50Z', '2012-06-04T12:00:00Z']).build()
//=> (modifiedTime = '2019-09-07T15:50Z' or modifiedTime = '2012-06-04T12:00:00Z')
Indicates whether the visibility level of the file is equal to the specified visibility level.
Type: VisibilityLevel | VisibilityLevel[]
VisibilityLevel.ANYONE_CAN_FIND
:
qb.getByVisibility(VisibilityLevel.ANYONE_CAN_FIND).build()
//=> (visibilityLevel = 'anyoneCanFind')
VisibilityLevel.ANYONE_WITH_LINK
:
qb.getByVisibility(VisibilityLevel.ANYONE_WITH_LINK).build()
//=> (visibilityLevel = 'anyoneWithLink')
VisibilityLevel.DOMAIN_CAN_FIND
:
qb.getByVisibility(VisibilityLevel.DOMAIN_CAN_FIND).build()
//=> (visibilityLevel = 'domainCanFind')
VisibilityLevel.DOMAIN_WITH_LINK
:
qb.getByVisibility(VisibilityLevel.DOMAIN_WITH_LINK).build()
//=> (visibilityLevel = 'domainWithLink')
VisibilityLevel.LIMITED
:
qb.getByVisibility(VisibilityLevel.LIMITED).build()
//=> (visibilityLevel = 'limited')
Indicates whether the file has the specified public properties.
Type: Record<string, unknown>
qb.getByPublicProp({
name: 'wrench',
mass: 1.3 // kg
}).build()
//=> (properties has { key='name' and value='wrench' } and properties has { key='mass' and value='1.3' })
Indicates whether the file has the specified private properties.
Type: Record<string, unknown>
qb.getByPrivateProp({
deviceId: 'd65dd82e-46fe-448f-a6fd-96009a8f97e4'
}).build()
//=> (appProperties has { key='deviceId' and value='d65dd82e-46fe-448f-a6fd-96009a8f97e4' })
Indicates whether the file is in the trash or not.
qb.isTrashed(true).build()
//=> (trashed = true)
Indicates whether the file is starred or not.
qb.isStarred(true).build()
//=> (starred = true)
isHidden(boolean)
Indicates whether the shared drive is hidden or not.
qb.isHidden(true).build()
//=> (hidden = true)
Negate the immediately following input (query).
qb.not().getByCollection(Collection.PARENTS, 'parent-id').build()
//=> not ('parent-id' in parents)
qb.not().getByCollection(Collection.PARENTS, ['parent-1', 'parent-2']).build()
//=> not ('parent-1' in parents or 'parent-2' in parents)
Joins the inputs into a single string with the and
operator.
qb.getByCollection(Collection.PARENTS, 'parent-id')
qb.getByFileName('something')
qb.build()
//=> ('parent-id' in parents) and (name = 'something')
© 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.