app

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Version can be set via build flags and
	// defines the version printed for the
	// `-v` flag.
	Version string

	// APIVersion can be set via the build flags
	// and defines the API version FDB uses.
	APIVersion = 620
)
View Source
var FDBQ = &cobra.Command{
	Use:     "fdbq [flags] query ...",
	Short:   "fdbq is a query language for Foundation DB",
	Version: Version,

	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) > 0 {
			return errors.New("unexpected positional args")
		}

		log := zerolog.Nop()
		if flags.Log {
			var writer io.Writer = zerolog.ConsoleWriter{
				Out:         os.Stderr,
				FormatLevel: func(_ interface{}) string { return "" },
			}
			if flags.Fullscreen() {
				file, err := os.Create(flags.LogFile)
				if err != nil {
					return errors.Wrap(err, "failed to open logging file")
				}
				defer func() {
					if err := file.Close(); err != nil {
						fmt.Println(errors.Wrap(err, "failed to close logging file"))
					}
				}()
				writer = file
			}
			log = zerolog.New(writer).With().Timestamp().Logger()
		}

		log.Log().Str("cluster file", flags.Cluster).Msg("connecting to DB")
		if err := fdb.APIVersion(APIVersion); err != nil {
			return errors.Wrap(err, "failed to set FDB API version")
		}
		db, err := fdb.OpenDatabase(flags.Cluster)
		if err != nil {
			return errors.Wrap(err, "failed to connect to DB")
		}

		eg := engine.New(
			facade.NewTransactor(db, directory.Root()),
			engine.ByteOrder(flags.ByteOrder()),
			engine.Logger(log))

		fmt := format.New(flags.FormatOpts()...)
		out := os.Stdout

		if flags.Fullscreen() {
			app := fullscreen.App{
				Engine: eg,
				Format: fmt,
				Log:    log,
				Out:    out,

				Write:      flags.Write,
				SingleOpts: flags.SingleOpts(),
				RangeOpts:  flags.RangeOpts(),
			}
			return app.Run(cmd.Context())
		}

		app := headless.App{
			Engine: eg,
			Format: fmt,
			Out:    out,

			Write:      flags.Write,
			SingleOpts: flags.SingleOpts(),
			RangeOpts:  flags.RangeOpts(),
		}
		return app.Run(cmd.Context(), flags.Queries)
	},
}

Functions

This section is empty.

Types

type Flags added in v0.4.0

type Flags struct {
	Cluster string
	Write   bool
	Log     bool
	LogFile string

	Queries []string
	Reverse bool
	Strict  bool
	Little  bool
	Bytes   bool
	Limit   int
}

func SetupFlags added in v0.4.0

func SetupFlags(cmd *cobra.Command) *Flags

func (*Flags) ByteOrder added in v0.4.0

func (x *Flags) ByteOrder() binary.ByteOrder

func (*Flags) FormatOpts added in v0.4.0

func (x *Flags) FormatOpts() []format.Option

func (*Flags) Fullscreen added in v0.4.0

func (x *Flags) Fullscreen() bool

func (*Flags) RangeOpts added in v0.4.0

func (x *Flags) RangeOpts() engine.RangeOpts

func (*Flags) SingleOpts added in v0.4.0

func (x *Flags) SingleOpts() engine.SingleOpts

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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