Sha256: 821c959b089bf59db6d912ab64b7b95c87291fffcc0d16a6b100a98c2c74fd48

Contents?: true

Size: 1.3 KB

Versions: 15

Compression:

Stored size: 1.3 KB

Contents

def evaluate_query(driver, src, opts = {})
  ss = StringScanner.new(src.dup)
  buf = ''

  until ss.eos?
    if (tok = ss.scan %r{[^`'";\\/#]+}) #'
      buf << tok
    elsif (tok = ss.scan /`(?:[^`]|``)*`/)
      buf << tok
    elsif (tok = ss.scan /'(?:[^']|'')*'/) #'
      buf << tok
    elsif (tok = ss.scan /"(?:[^"]|"")*"/) #"
      buf << tok
    elsif (tok = ss.scan %r{/\*/?(?:\n|[^/]|[^*]/)*\*/})
      # nothing to do
    elsif (tok = ss.scan /--[^\r\n]*(?:\r\n|\r|\n|\Z)/)
      # nothing to do
    elsif (tok = ss.scan /#[^\r\n]*(?:\r\n|\r|\n|\Z)/)
      # nothing to do
    elsif (tok = ss.scan /(?:\\;)/)
      buf << ';' # escape of ';'
    elsif (tok = ss.scan /(?:;|\\G)/)
      src.replace(ss.rest)
      query = buf
      buf = ''

      if query.strip.empty?
        print_error('No query specified')
        next
      end

      start_time = Time.new
      out = driver.execute(query)
      elapsed = Time.now - start_time

      if out.kind_of?(DynamoDB::Driver::Rownum)
        print_rownum(out, :time => elapsed)
      elsif out.kind_of?(String)
        puts out
      elsif out
        opts = opts.merge(:inline => (tok != '\G'), :time => elapsed)
        print_json(out, opts)
      end
    elsif (tok = ss.scan /./)
      buf << tok # 落ち穂拾い
    end
  end

  src.replace(buf.strip)
  buf
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ddbcli-0.2.4 lib/ddbcli/cli/evaluate.rb
ddbcli-0.2.3 lib/ddbcli/cli/evaluate.rb
ddbcli-0.2.2 lib/ddbcli/cli/evaluate.rb
ddbcli-0.2.1 lib/ddbcli/cli/evaluate.rb
ddbcli-0.2.0 lib/ddbcli/cli/evaluate.rb
ddbcli-0.1.9 lib/ddbcli/cli/evaluate.rb
ddbcli-0.1.8 lib/ddbcli/cli/evaluate.rb
ddbcli-0.1.7 lib/ddbcli/cli/evaluate.rb
ddbcli-0.1.6 lib/ddbcli/cli/evaluate.rb
ddbcli-0.1.5 lib/ddbcli/cli/evaluate.rb
ddbcli-0.1.4 lib/ddbcli/cli/evaluate.rb
ddbcli-0.1.3 lib/ddbcli/cli/evaluate.rb
ddbcli-0.1.2 lib/ddbcli/cli/evaluate.rb
ddbcli-0.1.1 lib/ddbcli/cli/evaluate.rb
ddbcli-0.1.0 lib/ddbcli/cli/evaluate.rb