Sha256: a5493b306a2961b2ba80f1ab3db84e6ad3daceda2b6f9a25d33239f575538e7f

Contents?: true

Size: 1.36 KB

Versions: 22

Compression:

Stored size: 1.36 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, opts.merge(:inline => (tok != '\G')))
      elapsed = Time.now - start_time

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

  src.replace(buf.strip)
  buf
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
ddbcli-0.6.0 lib/ddbcli/cli/evaluate.rb
ddbcli-0.5.4 lib/ddbcli/cli/evaluate.rb
ddbcli-0.5.3 lib/ddbcli/cli/evaluate.rb
ddbcli-0.5.2 lib/ddbcli/cli/evaluate.rb
ddbcli-0.5.1 lib/ddbcli/cli/evaluate.rb
ddbcli-0.5.0 lib/ddbcli/cli/evaluate.rb
ddbcli-0.5.0.beta lib/ddbcli/cli/evaluate.rb
ddbcli-0.4.2.beta2 lib/ddbcli/cli/evaluate.rb
ddbcli-0.4.2.beta lib/ddbcli/cli/evaluate.rb
ddbcli-0.4.1 lib/ddbcli/cli/evaluate.rb
ddbcli-0.4.0 lib/ddbcli/cli/evaluate.rb
ddbcli-0.3.8 lib/ddbcli/cli/evaluate.rb
ddbcli-0.3.7 lib/ddbcli/cli/evaluate.rb
ddbcli-0.3.6 lib/ddbcli/cli/evaluate.rb
ddbcli-0.3.5 lib/ddbcli/cli/evaluate.rb
ddbcli-0.3.4 lib/ddbcli/cli/evaluate.rb
ddbcli-0.3.3 lib/ddbcli/cli/evaluate.rb
ddbcli-0.3.2 lib/ddbcli/cli/evaluate.rb
ddbcli-0.3.1 lib/ddbcli/cli/evaluate.rb
ddbcli-0.3.0 lib/ddbcli/cli/evaluate.rb