fscli

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: MIT Imports: 20 Imported by: 0

README

fscli

A cli tool for firestore

Demo

fscli-demo

Installation

Download binary from Releases

or

go install github.com/maruware/fscli/cmd/fscli@latest

Prepare

$ gcloud auth application-default login

Usage

Basic
$ fscli --project-id my-project
> QUERY users
+----------------------+---------+-----+
|          ID          |  name   | age |
+----------------------+---------+-----+
| VfsA2DjQOWQmJ1LI8Xee | shigeru |  20 |
| ewpSGf5URC1L1vPENbxh | takashi |  20 |
+----------------------+---------+-----+
> QUERY users WHERE age = 20
+----------------------+---------+-----+
|          ID          |  name   | age |
+----------------------+---------+-----+
| VfsA2DjQOWQmJ1LI8Xee | shigeru |  20 |
| ewpSGf5URC1L1vPENbxh | takashi |  20 |
+----------------------+---------+-----+
> QUERY users WHERE name = "takashi" AND age = 20;
+----------------------+---------+-----+
|          ID          |  name   | age |
+----------------------+---------+-----+
| ewpSGf5URC1L1vPENbxh | takashi |  20 |
+----------------------+---------+-----+
> GET users/ewpSGf5URC1L1vPENbxh
+----------------------+---------+-----+
|          ID          |  name   | age |
+----------------------+---------+-----+
| ewpSGf5URC1L1vPENbxh | takashi |  20 |
+----------------------+---------+-----+
> QUERY users SELECT name WHERE age = 20 ORDER BY name ASC LIMIT 1
+----------------------+---------+
|          ID          |  name   |
+----------------------+---------+
| VfsA2DjQOWQmJ1LI8Xee | shigeru |
+----------------------+---------+
> QUERY posts WHERE tags ARRAY_CONTAINS 'tech'
+----------------------+------------+----------------+
|          ID          |   title    |      tags      |
+----------------------+------------+----------------+
| nOsNxixUQ1rqNwVJz56O | First post | [tech finance] |
+----------------------+------------+----------------+
> COUNT users
2
> COUNT users WHERE name = "takashi"
1
> \d
users
posts
groups
> \d groups/yvPWOCcd4CvfUr2POuXk
members
JSON mode
$ fscli --project-id my-project --out-mode json
> QUERY users
ID: VfsA2DjQOWQmJ1LI8Xee
Data: {"age":20,"name":"shigeru"}
--------------------------------------------------------------------------
ID: ewpSGf5URC1L1vPENbxh
Data: {"age":20,"name":"takashi"}
--------------------------------------------------------------------------

Documentation

Index

Constants

View Source
const (
	VENDOR_NAME  = "maruware"
	APP_NAME     = "fscli"
	HISTORY_FILE = "history"
)
View Source
const (
	EOF     = "EOF"
	ILLEGAL = "ILLEGAL"

	GET    = "GET"
	QUERY  = "QUERY"
	COUNT  = "COUNT"
	SELECT = "SELECT"

	WHERE              = "WHERE"
	EQ                 = "="
	NOT_EQ             = "!="
	GT                 = ">"
	GTE                = ">="
	LT                 = "<"
	LTE                = "<="
	IN                 = "IN"
	ARRAY_CONTAINS     = "ARRAY_CONTAINS"
	ARRAY_CONTAINS_ANY = "ARRAY_CONTAINS_ANY"
	ORDER              = "ORDER"
	BY                 = "BY"

	ASC  = "ASC"
	DESC = "DESC"

	IDENT  = "IDENT"
	STRING = "STRING"
	INT    = "INT"
	FLOAT  = "FLOAT"

	AND = "AND"

	LIMIT = "LIMIT"

	LBRACKET = "["
	RBRACKET = "]"
	COMMA    = ","

	LIST_COLLECTIONS = "LIST_COLLECTIONS"
	PAGER            = "PAGER"
)
View Source
const LongLine = "--------------------------------------------------------------------------"
View Source
const PAGE_SIZE = 100

Variables

View Source
var ErrInvalidCollection = errors.New("invalid collection")

Functions

This section is empty.

Types

type ArrayFilter added in v0.2.0

type ArrayFilter struct {
	BaseFilter
	// contains filtered or unexported fields
}

func NewArrayFilter added in v0.2.0

func NewArrayFilter(field string, operator Operator, value []any) *ArrayFilter

func (*ArrayFilter) Value added in v0.2.0

func (f *ArrayFilter) Value() any

type BaseFilter

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

func (*BaseFilter) FieldName

func (f *BaseFilter) FieldName() string

func (*BaseFilter) Operator

func (f *BaseFilter) Operator() Operator

type BaseMetacommand added in v0.7.0

type BaseMetacommand struct {
}

func (*BaseMetacommand) Type added in v0.7.0

func (m *BaseMetacommand) Type() string

type BaseOperation added in v0.7.0

type BaseOperation struct {
}

func (*BaseOperation) Type added in v0.7.0

func (op *BaseOperation) Type() string

type Completer added in v0.5.4

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

func NewCompleter added in v0.5.4

func NewCompleter(l *Lexer, findCollections func(baseDoc string) ([]string, error)) *Completer

func (*Completer) Parse added in v0.5.4

func (c *Completer) Parse() ([]prompt.Suggest, error)

type CountOperation added in v0.8.0

type CountOperation struct {
	BaseOperation
	// contains filtered or unexported fields
}

func NewCountOperation added in v0.8.0

func NewCountOperation(collection string, filters []Filter) *CountOperation

func (*CountOperation) Collection added in v0.8.0

func (op *CountOperation) Collection() string

func (*CountOperation) OperationType added in v0.8.0

func (op *CountOperation) OperationType() OperationType

type Executor

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

func NewExecutor

func NewExecutor(ctx context.Context, fs *firestore.Client) *Executor

func (*Executor) ExecuteCount added in v0.8.0

func (exe *Executor) ExecuteCount(ctx context.Context, op *CountOperation) (int64, error)

func (*Executor) ExecuteGet added in v0.3.0

func (exe *Executor) ExecuteGet(ctx context.Context, op *GetOperation) (*firestore.DocumentSnapshot, error)

func (*Executor) ExecuteListCollections added in v0.7.0

func (exe *Executor) ExecuteListCollections(ctx context.Context, cmd *MetacommandListCollections) ([]string, error)

func (*Executor) ExecuteQuery

func (exe *Executor) ExecuteQuery(ctx context.Context, op *QueryOperation) ([]*firestore.DocumentSnapshot, error)

type Filter

type Filter interface {
	FieldName() string
	Operator() Operator
	Value() any
}

type FloatFilter

type FloatFilter struct {
	BaseFilter
	// contains filtered or unexported fields
}

func NewFloatFilter

func NewFloatFilter(field string, operator Operator, value float64) *FloatFilter

func (*FloatFilter) Value

func (f *FloatFilter) Value() any

type GetOperation added in v0.3.0

type GetOperation struct {
	BaseOperation
	// contains filtered or unexported fields
}

func NewGetOperation added in v0.3.0

func NewGetOperation(collection string, docId string) *GetOperation

func (*GetOperation) Collection added in v0.3.0

func (op *GetOperation) Collection() string

func (*GetOperation) DocId added in v0.3.0

func (op *GetOperation) DocId() string

func (*GetOperation) OperationType added in v0.3.0

func (op *GetOperation) OperationType() OperationType

type IntFilter

type IntFilter struct {
	BaseFilter
	// contains filtered or unexported fields
}

func NewIntFilter

func NewIntFilter(field string, operator Operator, value int) *IntFilter

func (*IntFilter) Value

func (f *IntFilter) Value() any

type Lexer

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

func NewLexer

func NewLexer(input string) *Lexer

func (*Lexer) NextToken

func (l *Lexer) NextToken() Token

type Metacommand added in v0.7.0

type Metacommand interface {
	Type() string
	MetacommandType() string
}

type MetacommandListCollections added in v0.7.0

type MetacommandListCollections struct {
	BaseMetacommand
	// contains filtered or unexported fields
}

func (*MetacommandListCollections) MetacommandType added in v0.7.0

func (m *MetacommandListCollections) MetacommandType() string

type MetacommandPager added in v0.7.0

type MetacommandPager struct {
	BaseMetacommand
	// contains filtered or unexported fields
}

func (*MetacommandPager) MetacommandType added in v0.7.0

func (m *MetacommandPager) MetacommandType() string

type Operation

type Operation interface {
	Type() string
	OperationType() OperationType
	Collection() string
}

type OperationType added in v0.3.0

type OperationType string
const (
	OPERATION_TYPE_QUERY OperationType = "QUERY"
	OPERATION_TYPE_GET   OperationType = "GET"
	OPERATION_TYPE_COUNT OperationType = "COUNT"
)

type Operator added in v0.2.0

type Operator string
const (
	OPERATOR_EQ                 Operator = "=="
	OPERATOR_NOT_EQ             Operator = "!="
	OPERATOR_GT                 Operator = ">"
	OPERATOR_GTE                Operator = ">="
	OPERATOR_LT                 Operator = "<"
	OPERATOR_LTE                Operator = "<="
	OPERATOR_IN                 Operator = "in"
	OPERATOR_ARRAY_CONTAINS     Operator = "array-contains"
	OPERATOR_ARRAY_CONTAINS_ANY Operator = "array-contains-any"
)

type OrderBy added in v0.5.2

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

type OutputMode added in v0.4.0

type OutputMode string
const (
	OutputModeJSON  OutputMode = "json"
	OutputModeTable OutputMode = "table"
)

type ParseResult added in v0.7.0

type ParseResult interface {
	Type() string
}

type Parser

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

func NewParser

func NewParser(l *Lexer) *Parser

func (*Parser) Errors

func (p *Parser) Errors() []string

func (*Parser) Parse

func (p *Parser) Parse() (ParseResult, error)

type QueryOperation

type QueryOperation struct {
	BaseOperation
	// contains filtered or unexported fields
}

func NewQueryOperation

func NewQueryOperation(collection string, selects []string, filters []Filter, orderBys []OrderBy, limit int) *QueryOperation

func (*QueryOperation) Collection

func (op *QueryOperation) Collection() string

func (*QueryOperation) OperationType

func (op *QueryOperation) OperationType() OperationType

type Repl added in v0.4.0

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

func NewRepl added in v0.4.0

func NewRepl(ctx context.Context, fs *firestore.Client, in io.Reader, out io.Writer, outputMode OutputMode) *Repl

func (*Repl) Start added in v0.4.0

func (r *Repl) Start()

type StringFilter

type StringFilter struct {
	BaseFilter
	// contains filtered or unexported fields
}

func NewStringFilter

func NewStringFilter(field string, operator Operator, value string) *StringFilter

func (*StringFilter) Value

func (f *StringFilter) Value() any

type Token

type Token struct {
	Type    TokenType
	Literal string
}

type TokenType

type TokenType = string

func LookupIdent

func LookupIdent(ident string) TokenType

func LookupMetacommand added in v0.7.0

func LookupMetacommand(s string) TokenType

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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