/query-builder-for-driveapi

Easily generate queries for the Google Drive™ API.

Primary LanguageTypeScriptMIT LicenseMIT

query-builder-for-driveapi

Easily generate queries for the Google Drive™ API.

license node-current version unpacked-size downloads

Installation

npm install query-builder-for-driveapi

Get Started

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'

Basic Usage

// 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.

Method for Collections

CollectionMethod
parents
collection({
  [K in Collection]?: string | string[]
})
owners
writers
readers

Methods for fields

FieldOperator (if applicable)Method
name
  • Equal to (=): $eq
  • Not equal to (≠): $ne
  • Contains (⊇): $contains
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
  • Equal to (=): $eq
  • Not equal to (≠): $ne
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
  • Equal to (=): $eq
  • Not equal to (≠): $ne
  • Less than (<): $lt
  • Less than or equal to (≤): $lte
  • Greater than (>): $gt
  • Greater than or equal to (≥): $gte
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[]
})

Other Methods

MethodSample
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()

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.