0.1.0 • Published 4 years ago

@yagisumi/groonga-command v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

@yagisumi/groonga-command

This package is a port of groonga-command and groonga-command-parser

NPM version install size DefinitelyTyped
Build Status Coverage percentage

Installation

$ npm i @yagisumi/groonga-command

Usage

  • typescript
import { createCommand, TypeGuards, parseCommand } from '@yagisumi/groonga-command'

const command = createCommand('select', { table: 'Users' })
console.log(command.command_name) // 'select'
if (TypeGuards.isSelect(command)) {
  console.log(command.table) // 'Users'
}

const table_create = parseCommand('table_create Paths TABLE_HASH_KEY|KEY_LARGE ShortText')
if (table_create) {
  console.log(table_create.arguments)
  // [Object: null prototype] {
  //   name: 'Paths',
  //   flags: 'TABLE_HASH_KEY|KEY_LARGE',
  //   key_type: 'ShortText',
  // }
}

API

createCommand

function createCommand(
  command_name: string, 
  pair_arguments: { [name: string]: string }, 
  ordered_arguments?: string[]
): GroongaCommand

Creates a command object. Same as new GroongaCommand(command_name, pair_arguments, ordered_arguments)

parseCommand

function parseCommand(
  command_line: string,
  pair_arguments?: { [name: string]: string | number } // Overwrite arguments
): GroongaCommand | undefined

Returns GroongaCommand if parsing is successful, otherwise returns undefined.

License

MIT License