sequel

How do I define an ARRAY column in a Sequel Postgresql migration?

陌路散爱 提交于 2019-12-05 05:21:10
I am creating a Sequel migration to create a new table in my PostgreSQL database. I want to define a String array column, which PostgreSQL supports. My migration looks like this: create_table :venues do primary_key :id String :reference , :null => false String :name , :null => false String :description , :null => false String[] :type , :null => false DateTime :created_at , :null => false DateTime :updated_at , :null => false end How can I define something like text[] in my migration? You just use the column method and specify the type as a string: column :type, "text[]" 来源: https:/

Using UTC with Sequel?

社会主义新天地 提交于 2019-12-05 00:11:32
问题 I'd like to not store times in my local timezone, but Sequel is making it really tough on me. I can set them to UTC before I put them in there (a bit of a pain), but then when I take them back out it assumes that they are local dates and then they are all 8 hours in the future. Is this something that hasn't been implemented yet? And if so, are there any workarounds? Thanks! 回答1: The easiest way to try to put them in as UTC is to override literal_datetime and/or literal_time for the dataset

How to put a raw SQL query in Sequel

人走茶凉 提交于 2019-12-04 06:32:22
问题 I am trying to convert SQL code to Seqel to run it from my script. How do I convert this: select code, count(1) as total from school_districts group by code order by total desc; into Sequel? Or, is there a way to pass raw SQL to Sequel? Also the school_districts will be interpolated #{table_name} . 回答1: You can do it a couple ways: Use [] : DB["your sql string"] Use fetch : DB.fetch("your sql string") 回答2: DB[:school_districts].select(:code).group_and_count(:code).reverse_order(:count) is a

Sequel: How to use group and count

人盡茶涼 提交于 2019-12-04 05:20:42
Simply put, how can I do this query using Sequel ? select a.id, count(t.id) from albums a right join tracks t on t.album_id = a.id group by a.id DB[:albums___a]. right_join(:tracks___t, :album_id=>:id). select_group(:a__id). select_more{count(:t__id)} Your problem is that the left join finds a track ID for each album ID. Solutions: right join subquery of sums, assuming sequel supports that: left join (select album_id, count(album_id) as count from tracks group by album_id) t on a strait up from albums a, tracks t where t.album_id=a.id instead of the join. 来源: https://stackoverflow.com

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

狂风中的少年 提交于 2019-12-04 04:42:52
问题 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

Using UTC with Sequel?

允我心安 提交于 2019-12-03 15:07:32
I'd like to not store times in my local timezone, but Sequel is making it really tough on me. I can set them to UTC before I put them in there (a bit of a pain), but then when I take them back out it assumes that they are local dates and then they are all 8 hours in the future. Is this something that hasn't been implemented yet? And if so, are there any workarounds? Thanks! The easiest way to try to put them in as UTC is to override literal_datetime and/or literal_time for the dataset class you are using to return a literal string of the UTC time. Getting them out in UTC depends on the adapter

Sequel accessing many_to_many join table when adding association

谁都会走 提交于 2019-12-03 13:46:37
问题 I'm building a wishlist system using Sequel. I have a wishlists and items table and an items_wishlists join table (that name is what sequel chose). The items_wishlists table also has an extra column for a facebook id (so I can store opengraph actions), which is a NOT NULL column. I also have Wishlist and Item models with the sequel many_to_many association set up. The Wishlist class also has the :select option of the many_to_many association set to select: [:items.*, :items_wishlists_

Are there any Ruby ORMs which use cursors or smart fetch?

谁说胖子不能爱 提交于 2019-12-03 11:08:46
问题 I'm looking for a Ruby ORM to replace ActiveRecord. I've been looking at Sequel and DataMapper. They look pretty good however none of them seems to do the basic: not loading everything in memory when you don't need it. I mean I've tried the following (or equivalent) on ActiveRecord and Sequel on table with lots of rows: posts.each { |p| puts p } Both of them go crazy on memory. They seem to load everything in memory rather than fetching stuff when needed. I used the find_in_batches in

Sequel accessing many_to_many join table when adding association

五迷三道 提交于 2019-12-03 03:45:47
I'm building a wishlist system using Sequel. I have a wishlists and items table and an items_wishlists join table (that name is what sequel chose). The items_wishlists table also has an extra column for a facebook id (so I can store opengraph actions), which is a NOT NULL column. I also have Wishlist and Item models with the sequel many_to_many association set up. The Wishlist class also has the :select option of the many_to_many association set to select: [:items.*, :items_wishlists__facebook_action_id] . Is there a way that I can add in extra data when creating the association, like wishlist

MacRuby, error when using Sequel

99封情书 提交于 2019-12-02 11:21:29
问题 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