Sha256: d2520794abe2a0ee1f33d337351db0df70f1d49fa894e9d09b796cd5c429cbab

Contents?: true

Size: 646 Bytes

Versions: 2

Compression:

Stored size: 646 Bytes

Contents

# frozen_string_literal: true

require "csvsql/version"

require 'csv'
require 'sqlite3'

require 'csvsql/db'
require 'csvsql/tracker'

module Csvsql
  def self.execute(sql, csv_data, opts = {})
    encoding = opts.delete(:encoding)
    csvdb = Csvsql::Db.new(opts)
    csvdb.import(csv_data, encoding: encoding)
    pst = Csvsql::Tracker.commit(:execute_query_sql) do
      csvdb.prepare(sql)
    end
    Csvsql::Tracker.commit(:output_format)
    CSV.generate do |csv|
      csv << pst.columns.zip(pst.types).map { |c| c.compact.join(':') }
      pst.each { |line| csv << line }
    end.tap { Csvsql::Tracker.commit(:output_format) }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
csvsql-0.1.5 lib/csvsql.rb
csvsql-0.1.4 lib/csvsql.rb