Dri
Dri

Reputation: 672

Have you successfully used Sequel as an ORD with Snowflake?

I'm building a RoR application that will extract data from Snowflake and serve it via a REST endpoint. I have successfully connected to the Snowflake data source to get the data that I need and extract individual records in a format like this:

    db = Sequel.odbc('snowflake')
    db.fetch('SELECT * FROM "BILLABLE_ITEMS"."USAGES";') do |row|
      Rails.logger.debug row
    end

What I would like to do is to use this connection as Sequel models as outlined here:

class Post < Sequel::Model
end
post = Post.new

The part that is throwing me off, to begin with, is how to tell Sequel that the model Usage should map to the table "BILLABLE_ITEMS"."USAGES" and not simply USAGES the way it would be in PostgreSQL for example. I'm not aware of a place where I can map that out, but this would greatly help reduce the "special casing" and learnability of the code dealing with Snowflake in my RoR application.

I tried this:

require 'odbc'
require 'sequel'

SNOWFLAKE = Sequel.odbc('snowflake')

module Sft
  class AllDailyUsage < Sequel::Model(Sequel.qualify(:BILLABLE_ITEMS, :USAGES))
  end
end

Sft::AllDailyUsage.db = SNOWFLAKE

Unfortunately, now I get this:

Sft::AllDailyUsage.last
#<Sequel::Error: Cannot use Sequel::Model.db= on model with existing dataset.  Use Sequel::Model.dataset= instead.>

Very puzzled about how to use datasets with odbc.

Upvotes: 0

Views: 72

Answers (0)

Related Questions