sequel

Moving table columns to new table and referencing as foreign key in PostgreSQL

两盒软妹~` 提交于 2019-12-13 05:37:37
问题 Suppose we have a DB table with fields "id", "category", "subcategory", "brand", "name", "description", etc. What's a good way of creating separate tables for (eg.) "category", "subcategory" and "brand" and the corresponding columns and rows in the original table becoming foreign key references? To outline the operations envolved: - get all unique values in each column of the original table which should become foreign keys; - create tables for those - create foreign key reference columns in

Recursive logic for parsing string into complex boolean?

那年仲夏 提交于 2019-12-12 03:46:50
问题 I'm sure this has been done before, I just can't find it. I need to turn something like, "((A OR B) AND C) OR D" into a database query for an attribute. Specifically I'm using Ruby Sequel. Can anyone point me at an example or utility or something that will keep me from reinventing the wheel? 回答1: You can define a grammar using ANTLR and automatically generate a Ruby parser for those type of strings. ANTLR is a parser generator and it allows you to define a grammar for a language (such as a

How do we verify if Sequel.connect opened our SQLite3 database in Rails?

﹥>﹥吖頭↗ 提交于 2019-12-11 12:29:53
问题 We are trying to find out if our Rails 3.1.12 app opens the SQLite3 database (version 3.6 or above) with gem sequel. Here is what we did: rails console In the Rails console session, typed the following command: sequel = Sequel.connect('sqlite://development') It returns: => #<Sequel::SQLite::Database: "sqlite://development"> Also sequel.class returns: => Sequel::SQLite::Database However when trying to select from the database with sequel.execute or check a table with sequel.schema , the

Any suggestions for a ruby solution for populating a sqlite database from a mysql source

那年仲夏 提交于 2019-12-11 07:05:39
问题 I have a Rails application that uses MySQL. The application needs to populate sqlite databases to be distributed to client applications from the master mysql database. The schema for the sqlite database will be very similar to the mysql database, but not identical. The sqlite databases will be populated with a subset of the schema and data stored in the master mysql database. The data subset will be determined by parameters passed in the http request. This is not intended as a maintenance

How do I find the sum of two categories for each year in this PostgreSQL dataset?

杀马特。学长 韩版系。学妹 提交于 2019-12-11 04:23:03
问题 Here's my dataset (in CSV form for easy reading): item_category,year,price "Bacon",1890,0.12 "Bacon",1891,0.126 "Bacon",1892,0.129 "Bacon",1893,0.142 "Eggs (dozen)",1890,0.208 "Eggs (dozen)",1891,0.221 "Eggs (dozen)",1892,0.221 "Eggs (dozen)",1893,0.224 I'd like to find the sum for the price of bacon and eggs for each year. So, the result I want would be: item_category,year,price "Bacon and eggs",1890,0.328 "Bacon and eggs",1891,0.347 "Bacon and eggs",1892,0.35 "Bacon and eggs",1893,0.366 I'm

sequel trying to use postgresql instead of postgres as adapters

拟墨画扇 提交于 2019-12-11 04:05:55
问题 Had a simple heroku app with sequel and postgres. However, I got: % heroku rake db:migrate rake aborted! LoadError: no such file to load -- sequel/adapters/postgresql /app/.bundle/gems/ruby/1.9.1/gems/sequel-3.23.0/lib/sequel/core.rb:249:in `require' There is no postgresql.rb in the sequel-3.23.0/lib/sequel/adapters/ There is a postgres.rb on my local drive. I'm using the free plan. % heroku info ... Dynos: 1 Workers: 0 Repo size: 9M Slug size: 8M Stack: bamboo-mri-1.9.2 Data size: (empty)

Extracting month/year from Time Column in sqlite3 using Sequel

一曲冷凌霜 提交于 2019-12-11 03:05:41
问题 I have a table like this - db = Sequel.sqlite db.create_table? :timesheets do primary_key :id String :project Time :start end where I insert a record like so - db[:timesheets].insert(:project => 'AAA', :start => Time.now) How would I extract the 'year' from the entry? I tried the following - db[:timesheets].select(:strftime.sql_function('%Y', :start)).filter(:id => 1).first db[:timesheets].select(Sequel.extract(:month, :start)).filter(:id => 1).first db.fetch("SELECT strftime('%Y', start)

Ruby and MySQL UTF-8 characters

为君一笑 提交于 2019-12-10 21:25:34
问题 I'm switching a Sinatra application from SQLite3 to MySQL. For some reason, which I can't understand, when I extract data from the MySQL using Ruby and Sequel the characters appear in 8-BIT ASCII instead of UTF-8. The deployment environment is a FreeBSD 9.1 and MySQL 5.6.12, with a system-wide ruby19 installed from FreeBSD ports. RVM ruby-2.0p247 produces the same result though. My my.cnf is the following: # The following options will be passed to all MySQL clients [client] default-character

How to do a Sequel query with 'like'?

孤人 提交于 2019-12-10 19:24:48
问题 I'm trying to implement a form to search through the title of my posts. This is the controller code: post '/search' do @results = Post.all(:Title.like => "%#{params[:query]}%") erb :layout end This is the layout.erb code: <form action="/search" method="post"> <input type="text" name="query"/><br /> <input type="submit" /> </form> <% if @results %> <table> <%@results.each do |r|%> <tr valign="top"> <td><%=r.Title%></td> </tr> <%end%> </table> <% end %> I get an error saying 'undefined method

SQLite3::IOException: disk I/O error on SELECT

丶灬走出姿态 提交于 2019-12-10 17:11:42
问题 I have a Sinatra application using the Sequel gem against a sqlite3 database. I've been developing on a MacBook Pro running Mavericks. I have been running the app locally using the shotgun gem and everything has been working just fine. Recently I decided to run the application with Passenger and Nginx. When I run the application under passenger/nginx, the app errors out with the following in the logs App 17805 stdout: E, [2014-02-09T20:44:42.491448 #17805] ERROR -- : SQLite3::IOException: