Query Builder for DriveAPI

Easily generate queries for the Google Drive API.
Installation
npm install query-builder-for-driveapi
Importing
import QueryBuilder, { Collection, FileType, VisibilityLevel } from 'query-builder-for-driveapi'
const QueryBuilder = require('query-builder-for-driveapi')
const { Collection, FileType, VisibilityLevel } = QueryBuilder
Usage
const qb = new QueryBuilder()
qb.getByCollection(Collection.PARENTS, 'parent-id')
qb.getByFileName('something')
const query = qb.build()
API Reference
Constructor
Create an instance of QueryBuilder.
new QueryBuilder()
Methods
From now on all the examples of each method will use an instance of QueryBuilder
associated to the constant qb
.
getByCollection(collection, value)
Indicates whether the collection contains the specified values.
collection
Type: Collection
qb.getByCollection(Collection.PARENTS, ...).build()
qb.getByCollection(Collection.OWNERS, ...).build()
qb.getByCollection(Collection.WRITERS, ...).build()
qb.getByCollection(Collection.READERS, ...).build()
value
Type: string | string[]
qb.getByCollection(..., 'value').build()
qb.getByCollection(..., ['value-1', 'value-2']).build()
getByFileName(filename)
Indicates whether the file name is equal to the specified file name.
filename
Type: string | string[]
qb.getByFileName('value').build()
qb.getByFileName(['value-1', 'value-2']).build()
getByContent(value)
Indicates whether the file name, description, indexableText or content text properties or metadata of the file contains the specified value.
value
Type: string | string[]
qb.getByContent('value').build()
qb.getByContent(['value-1', 'value-2']).build()
getByFileType(filetype)
Indicates whether the MIME type of the file is equal to the specified file type.
filetype
Type: string | FileType | (string | FileType)[]
qb.getByFileType(FileType.FOLDER).build()
qb.getByFileType(FileType.DOCUMENT).build()
qb.getByFileType(FileType.SPREADSHEET).build()
qb.getByFileType(FileType.PRESENTATION).build()
qb.getByFileType(FileType.FORM).build()
qb.getByFileType('image/jpeg').build()
qb.getByFileType(['image/png', FileType.DOCUMENT]).build()
getByCreatedAt(timestamp)
Indicates whether the creation date of the file is equal to the specified timestamp.
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()
qb.getByCreatedAt(['2019-09-07T15:50Z', '2012-06-04T12:00:00Z']).build()
getByUpdatedAt(timestamp)
Indicates whether the modified date of the file is equal to the specified timestamp.
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()
qb.getByUpdatedAt(['2019-09-07T15:50Z', '2012-06-04T12:00:00Z']).build()
getByVisibility(visibilityLevel)
Indicates whether the visibility level of the file is equal to the specified visibility level.
visibilityLevel
Type: VisibilityLevel | VisibilityLevel[]
VisibilityLevel.ANYONE_CAN_FIND
:
qb.getByVisibility(VisibilityLevel.ANYONE_CAN_FIND).build()
VisibilityLevel.ANYONE_WITH_LINK
:
qb.getByVisibility(VisibilityLevel.ANYONE_WITH_LINK).build()
VisibilityLevel.DOMAIN_CAN_FIND
:
qb.getByVisibility(VisibilityLevel.DOMAIN_CAN_FIND).build()
VisibilityLevel.DOMAIN_WITH_LINK
:
qb.getByVisibility(VisibilityLevel.DOMAIN_WITH_LINK).build()
qb.getByVisibility(VisibilityLevel.LIMITED).build()
getByPublicProp(properties)
Indicates whether the file has the specified public properties.
properties
Type: Record<string, unknown>
qb.getByPublicProp({
name: 'wrench',
mass: 1.3
}).build()
getByPrivateProp(properties)
Indicates whether the file has the specified private properties.
properties
Type: Record<string, unknown>
qb.getByPrivateProp({
deviceId: 'd65dd82e-46fe-448f-a6fd-96009a8f97e4'
}).build()
isTrashed(boolean)
Indicates whether the file is in the trash or not.
qb.isTrashed(true).build()
isStarred(boolean)
Indicates whether the file is starred or not.
qb.isStarred(true).build()
isHidden(boolean)
Indicates whether the shared drive is hidden or not.
qb.isHidden(true).build()
not()
Negate the immediately following input (query).
qb.not().getByCollection(Collection.PARENTS, 'parent-id').build()
qb.not().getByCollection(Collection.PARENTS, ['parent-1', 'parent-2']).build()
build()
Joins the inputs into a single string with the and
operator.
qb.getByCollection(Collection.PARENTS, 'parent-id')
qb.getByFileName('something')
qb.build()
Copyright & License
© 2023 - Brian Fernandez
This project is licensed under the MIT license. See the file LICENSE for details.
Disclaimer
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.