sequel

MacRuby, error when using Sequel

吃可爱长大的小学妹 提交于 2019-12-02 03:54:24
I have just installed Sequel using the command sudo macgem install sequel . It tells me sequel-3.18.0 was successfully installed. When I fire up xcode, and start a new MacRuby application, it sets up a target for unit tests. I have modified stub_test.rb with the following two lines: require "rubygems" require "sequel" When trying to run the unit tests, I get the following error: /Users/.../macRuby Test/Tests/run_suite.rb:1:in `<main>': super: no superclass method `require' for Sequel:Class (NoMethodError) Without the two require statements, the tests run fine. I have tried to google this, and

Ruby Sequel: Array returned by query is being returned as a String object, not an Array object

邮差的信 提交于 2019-12-01 21:28:40
I'm using the pg_array extension of Ruby Sequel. When I select a column that is a Postgresql array, the result is a string in Ruby. How do I get this to be a Ruby array so I can use things like .each on it? CaseTypeCategory.first(category_name: 'Subscription')[:values] => "{value_one,value_two}" CaseTypeCategory.first(category_name: 'Subscription')[:values][0] => "{" Our database config includes: Sequel.extension :pg_array, :pg_inet, :pg_json And the migration to add the columns included this: alter_table :case_type_categories do add_column :values, "text[]" end I can write raw SQL to access

What ORM to use in one process multiple db connections sinatra application?

风格不统一 提交于 2019-11-30 21:45:41
Checked ActiveRecord, DataMapper, Sequel: some use globals (static variables) some require open db connection before loading source file with models. What ORM is better to use in sinatra application that uses different databases. DataMapper is designed for multi-database use. You can set up multiple repositories just by saying something like DataMapper.setup(:repository_one, "mysql://localhost/my_db_name") . DataMapper then tracks all the repositories that have been setup in a hash that you can reference and use for scoping: DataMapper.repository(:repository_one){ MyModel.all } (The default

heroku db:pull not working

拜拜、爱过 提交于 2019-11-30 15:29:38
问题 heroku db:pull postgresql://root:@localhost/db_name After this command display this message /usr/lib/ruby/gems/1.8/gems/rest-client-1.6.1/lib/restclient/abstract_response.rb:50: warning: parenthesize argument(s) for future version Loaded Taps v0.3.13 Warning: Data in the database 'postgresql://root:@localhost/db_name' will be overwritten and will not be recoverable. Are you sure you wish to continue? (y/n)? y Failed to connect to database: Sequel::AdapterNotFound -> LoadError: no such file to

heroku db:pull not working

荒凉一梦 提交于 2019-11-30 14:59:17
heroku db:pull postgresql://root:@localhost/db_name After this command display this message /usr/lib/ruby/gems/1.8/gems/rest-client-1.6.1/lib/restclient/abstract_response.rb:50: warning: parenthesize argument(s) for future version Loaded Taps v0.3.13 Warning: Data in the database 'postgresql://root:@localhost/db_name' will be overwritten and will not be recoverable. Are you sure you wish to continue? (y/n)? y Failed to connect to database: Sequel::AdapterNotFound -> LoadError: no such file to load -- sequel/adapters/postgresql How to use db:pull First, you need to fix your connection string:

sequel never returns utf-8, just ascii-8bit

一个人想着一个人 提交于 2019-11-30 08:41:04
There is this mysql database I'm trying to connect to. DataMapper fetches everything nicely in UTF-8 but Sequel always returns strings in ASCII-8bit which produces errors with .to_json. I have tried several things in order to get it to work. Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = Encoding::UTF_8 DB.run 'set names utf8' Sequel.mysql 'db', (...), :encoding => 'utf-8' I have gems: mysql (2.9.0) (tried without), mysql2 (0.3.11) and sequel (3.42.0) The only thing that works is manually forcing the encoding on every string which is MUCH less than ideal. Try Sequel

Slicing params hash for specific values

故事扮演 提交于 2019-11-29 03:35:26
Summary Given a Hash, what is the most efficient way to create a subset Hash based on a list of keys to use? h1 = { a:1, b:2, c:3 } # Given a hash... p foo( h1, :a, :c, :d ) # ...create a method that... #=> { :a=>1, :c=>3, :d=>nil } # ...returns specified keys... #=> { :a=>1, :c=>3 } # ...or perhaps only keys that exist Details The Sequel database toolkit allows one to create or update a model instance by passing in a Hash: foo = Product.create( hash_of_column_values ) foo.update( another_hash ) The Sinatra web framework makes available a Hash named params that includes form variables,

Encoding::UndefinedConversionError

喜欢而已 提交于 2019-11-28 18:12:43
I keep getting an Encoding::UndefinedConversionError - "\xC2" from ASCII-8BIT to UTF-8 every time I try to convert a hash into a JSON string. I tried with [.encode | .force_encoding](["UTF-8" | "ASCII-8BIT" ]) , chaining .encode with .force_encoding , backwards, switching parameters but nothing seemed to work so I caught the error like this: begin menu.to_json rescue Encoding::UndefinedConversionError puts $!.error_char.dump p $!.error_char.encoding end Where menu is a sequel's dataset.to_hash with content from a MySQL DB, utf8_general_ci encoding and returned this: "\xC2" <#Encoding:ASCII

Encoding::UndefinedConversionError

此生再无相见时 提交于 2019-11-27 11:06:52
问题 I keep getting an Encoding::UndefinedConversionError - "\xC2" from ASCII-8BIT to UTF-8 every time I try to convert a hash into a JSON string. I tried with [.encode | .force_encoding](["UTF-8" | "ASCII-8BIT" ]) , chaining .encode with .force_encoding , backwards, switching parameters but nothing seemed to work so I caught the error like this: begin menu.to_json rescue Encoding::UndefinedConversionError puts $!.error_char.dump p $!.error_char.encoding end Where menu is a sequel's dataset.to

Inserting an array using Sequel gem in PostgreSQL

自古美人都是妖i 提交于 2019-11-27 08:27:00
问题 i created a table with the following schema in code DB.create_table :Pokemon do primary_key :id String :first_name String :last_name String :email String :zipcode String :company_name String :google_profile String :skype String :phone String :about String :linkedin_profile_url String :company_url column :needs , 'Text[]' column :offering , 'Text[]' end for needs and offering i am inserting a string array with following code pokes=DB[:Pokemon]; off=['hello1' , 'hello2'] nee= ['need1' , 'need2'