fireql

package module
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2023 License: MIT Imports: 4 Imported by: 0

README

build Codecov Go Report Card GitHub go.mod Go version GitHub release (latest by date) PkgGoDev

FireQL

FireQL is the Golang library and interactive CLI tool to query the Google Firestore database using SQL syntax.

It is built on top of the official Google Firestore Client SDK that will allow running queries Cloud Firestore database using SQL syntax. Inspired by Firebase FireSQL.

fireql

Usage

FireQL can be used as Go library or interactive command-line tool.

Go Library

An example of querying collections using SQL syntax:

import (
    "github.com/pgollangi/fireql"
)

func main() {
    fql, err := fireql.New("<GCP_PROJECT_ID>")
    //OR
    fql, err = fireql.New("<GCP_PROJECT_ID>", fireql.OptionServiceAccount("<SERVICE_ACCOUNT_JSON>"))
    if err != nil {
        panic(err)
    }
    
	// Now, execute SELECT query
    result, err := fql.Execute("SELECT * `users` order by id desc limit 10")
    if err != nil {
        panic(err)
    }
    _ = result
}
Command-Line
fireql [flags]
Example
$ fireql --project $PROJECT_ID
Welcome! Use SQL to query Firestore.
Use Ctrl+D, type "exit" to exit.
Visit github.com/pgollangi/FireQL for more details.
fireql>select id, name from users limit 2
+------+------------+
|  ID  |    NAME    |
+------+------------+
| 1046 | bob        |
| 1047 | smith      |
+------+------------+
(2 rows)
fireql>

Read the documentation for more information on CLI usage.

Examples

Some cool SELECT queries that are possible with FireQL:

select * from users
select * from `[contacts]` // To query collection group. enclose subcollect name in square brackets.
select *, id as user_id from users
select id, email as email_address, `address.city` AS city from `users`
select * from users order by 'address.city' desc limit 10
select * from `users` where id > 50
select id, LENGTH(contacts) as total_contacts from `users`
select id, (age > 100) as centenarian as total_contacts from `users`
select __name__ from users // to select document id

FireQL depend on govaluate to evaluate expressions in SELECT. See list of possible expressions and operators here.

See Wiki for more examples.

Authentication

fireql.New assume Google Application Default Credentials to authenticate to Firestore database if serverAccount not passed. Otherwise use service account for authentication.

Installation

Homebrew
brew install pgollangi/tap/fireql

Updating:

brew upgrade fireql
Scoop (for windows)
scoop bucket add pgollangi-bucket https://github.com/pgollangi/scoop-bucket.git
scoop install fireql
Docker
docker run pgollangi/fireql
Go
go install github.com/pgollangi/fireql@latest
Manual

You can alternately download a suitable binary for your OS at the releases page.

Limitations

All of firestore query limitations are applicable when running queries using FireQL.

In addition to that:

  • Only SELECT queries for now. Support for INSERT, UPDATE, and DELETE might come in the future.
  • Only AND conditions supported in WHERE clause.
  • No support for JOINs.
  • LIMIT doesn't accept an OFFSET, only a single number.
  • No support of GROUP BY and aggregate function COUNT.

Future scope

  • Create an interactive command-line shell to run queries
  • Expand support for all logical conditions in WHERE clause by internally issuing multiple query requests to Firestore and merging results locally before returning.
  • GROUP BY support
  • Support other DML queries: INSERT, UPDATE, and DELETE

Run

Tests
$ go test ./...

Contributing

Thanks for considering contributing to this project!

Please read the Contributions and Code of conduct.

Feel free to open an issue or submit a pull request!

Licence

FireQL is open-sourced software licensed under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FireQL

type FireQL struct {
	// contains filtered or unexported fields
}

FireQL object is constructed to execute SQL queries on Firestore database. FireQL internally issue queries constructed from SQL on Firestore database using Google Firestore client library

func New added in v0.1.1

func New(projectId string, options ...Option) (*FireQL, error)

New creates new FireQL instance using the "projectId" passed. Accepts list of Option to pass other configuration params. Google Application Default Credentials are used by Firestore client library if service account is not passed via Option. See https://cloud.google.com/docs/authentication/client-libraries for more information about how Application Default Credentials are used by Google client libraries

func (*FireQL) Execute

func (fql *FireQL) Execute(query string) (*util.QueryResult, error)

Execute accepts SQL query as parameter, then parses, validates, construct and issue Firestore query to Google Firestore database. And parse results according field alias, return records.

type Option added in v0.1.1

type Option func(prompt *FireQL) error

Option is the type to replace default parameters. fireql.New accepts any number of options (this is functional option pattern).

func OptionDefaultLimit added in v0.1.1

func OptionDefaultLimit(limit int) Option

OptionDefaultLimit to use as the default limit of resulted records. Considered only when LIMIT not used in SQL query.

func OptionServiceAccount added in v0.1.1

func OptionServiceAccount(serviceAccount string) Option

OptionServiceAccount to set a service account to be used for Firestore authentication.

Directories

Path Synopsis
cmd
fireql command
gen-docs command
pkg
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL