Coder Social home page Coder Social logo

google-drive-query-builder's Introduction

Google Drive query builder

This package helps build search queries for Google Drive Search API.

Drive files.list API and search syntax are documented here:

Usage

The example below searches for documents matching the following criteria:

  • ( content-type is text/plain AND name includes "Foo" ) OR name is "pluto"
  • AND document was created less than 10 hours ago
package main

import (
	"context"
	"fmt"
	"log"
	q "gitlab.com/mxmz/google-drive-query-builder/query"
	"golang.org/x/oauth2/google"
	drive "google.golang.org/api/drive/v3"
)

func main() {

	var stm1 = q.MimeType().Equal("text/plain")
	var stm2 = q.Name().Contains("Foo")

	var query = q.
		Query(stm1).
		And(stm2).
		Or(q.Raw(`name = "pluto"`)).
		And(q.CreatedTime().After(time.Now().Add(-10 * time.Hour)))


	ctx := context.Background()
	client, _ := google.DefaultClient(ctx, drive.DriveScope)
	driveSvc, _ := drive.New(client)

	var svc = drive.NewFilesService(driveSvc)
	lst, _ := svc.List().
		Q(q.Stringize(query)).
		Fields("files(name,createdTime,properties)").
		OrderBy("createdTime").
		PageSize(1000).
		Do()

	for _, v := range lst.Files {

		log.Printf("%s %v \n", v.Name, v.CreatedTime)

	}


}

google-drive-query-builder's People

Contributors

mxmz avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.