Sequel does not support a :zerofill argument for defining columns. You may want to just specify the type directly using something like: column :ip_address_integer, 'integer(10) unsigned zerofill' ...
I think you want to use 2 arguments instead of a single hash, just as in your first example: dataset = candidates.where(:city => params['city'], :industry => params['industry']) dataset.full_text_search(:experience, params['search_term']).to_a.to_json ...
You can use the :include option of Sequel's to_json method to do this. You can specify this in the model when you set the json_serializer options, but you can also override those defaults when you call to_json on an instance. So, on an individual instance of Bar, you could do:...
Database#in_transaction? is apparently not accurate inside an after_commit block. But after_commit is definitely being called after the COMMIT happens, not before.
Assuming you have some user input as a string: user_input = 'a,b,c' and a posts table with a value1 column. You can get posts with values a, b or c with the following query: values = user_input.split(',') #=> ["a", "b", "c"] DB = Sequel.sqlite #=> #<Sequel::SQLite::Database: {:adapter=>:sqlite}> dataset = DB[:posts]...
You have a Sequel::MySQL::Dataset in @var, you can see that from the puts @var output. Sequel::MySQL::Dataset gets its [] method from Sequel::Dateset and that method: - (Object) [](*conditions) Returns the first record matching the conditions. Examples: DB[:table][:id=>1] # SELECT * FROM table WHERE (id = 1) LIMIT 1 # =>...
It looks like the Town class simply isn't loaded at the point when seeds.rb is running. If the comment from @SergioTulentsev didn't work, can you post your seeds file? Especially line 36 where the error is occurring? I'm guessing that on line 36 you reference the Town class, which isn't...
In general you want to look at the options for associations. Specifically, you need to tell Sequel how to find the correct 'bars' given a foo. If you are just using a non-standard name for the foreign key reference in your BAR_TABLE, you can do this: class Foo < Sequel::Model(:BAR_TABLE)...
The functionality you're looking for is provided by sequel enum gem. Checkout the README for implementation details. https://github.com/planas/sequel_enum...
mysql,ruby-on-rails,ruby,osx,sequel
STOP modifying the Apple-supplied Ruby unless you are absolutely sure of what you're doing. It was put there for Apple's use. We can piggy back on that, but don't change it, which would happen using sudo gem.... Use either rbenv or RVM to install and manage separate Rubies for...
postgresql,data-modeling,sequel
-- Some test data CREATE TABLE animals ( id SERIAL NOT NULL PRIMARY KEY , name varchar , category varchar , subcategory varchar ); INSERT INTO animals(name, category, subcategory) VALUES ( 'Chimpanzee' , 'mammals', 'apes' ) ,( 'Urang Utang' , 'mammals', 'apes' ) ,( 'Homo Sapiens' , 'mammals', 'apes'...
ruby-on-rails,ruby,postgresql-9.2,sequel
Sequel's json_serializer plugin already has support for associations via the :include option. Also, you need to fix your association. Something like this should work: Author.one_to_many :books Author.order(:id).to_json(:include=>:books) ...
ruby,escaping,sinatra,sequel,quoting
You could you quote to sanitize your string: puts $DB[:users].order_by( ("field = %s" % ActiveRecord::Base.connection.quote("'")).lit ).sql # SELECT * FROM `users` ORDER BY field = '''' For sequel you should use literal_append: puts $DB[:users].order_by( ($DB[:users].literal_append("field = ", "'")).lit ).sql # SELECT * FROM `users` ORDER BY field = '''' ...
The DSL where a line begins with a word, and then a list of parameters with a coma between them is actually a method call, so the original code is actually: DB.create_table :items do primary_key(:id) String(:name) Float(:price) end From the sequel documentation: Most method calls inside the create_table block will...
Try either of these @newnumber = number.find(:all, :conditions => ["id = ?", @dictionary.id], :select => "number * 2 as newnumber") @newnumber = number.all(:conditions=>"id='#{@dictionary.id}'",:select=>"number * 2 as newnumber") ...
ruby,database,sqlite,sinatra,sequel
As I researched, I found that there are many solutions to this problem. I'm going to use a basic and simplistic way. Within the Index.erb File, the code that is written above (<div> <%= @item %> </div>) is close to what the desired outcome is. Instead of just writing @item,...
Try Jeremy's counter cache https://github.com/jeremyevans/sequel_postgresql_triggers # In your migration: pgt_counter_cache :categories, :id, :posts_count, :posts, :category_id # And in your code: categories = Category.exclude(posts_count: 0).all The documentation isn't very good so here are the arguments: https://github.com/jeremyevans/sequel_postgresql_triggers/blob/master/lib/sequel_postgresql_triggers.rb#L27...
Use the pg_array_ops extension: Sequel.extension :pg_array_ops Email.where(Sequel.pg_array_op(:references).contains('[email protected]')) ...
First, some (ultimately unhelpful) basics. Sequel is letting you treat the model like a hash, insofar as you can store extra read-only values on it. However, as with Sequel's hashes returned from a dataset, just setting the key does not update it. For example: bob = DB[:users][name:'Bob'] #=> {:id=>1, :name=>"Bob"}...
Thanks user007. I ended up changing the query. SELECT CHRGCD FROM PACPTCD WHERE CHRGCD NOT IN (SELECT DISTINCT(CHRGC) FROM PACPTCD WHERE CCTRMDT='9999-01-01') Dozen ways to do it. This one is the easiest. Even easier than my original. ...
It doesn't appear as though @attendees in the first code block is the same as @attendees in the second code block. In the first code block, @attendees is set in what appears to be top-level code. In the second code block, @attendees is used inside a route, which is going...
You probably want to call Author.all_association_reflections to get metadata on associations (db_schema just gives column schema metadata). See http://sequel.jeremyevans.net/rdoc/files/doc/reflection_rdoc.html for details on Sequel's reflection methods.
this should do it select County, Year(dDate) as Year, count(*) as Total, sum(case when DATEPART(q, dDate)=1 then 1 else 0 end) as Q1, sum(case when DATEPART(q, dDate)=2 then 1 else 0 end) as Q2, sum(case when DATEPART(q, dDate)=3 then 1 else 0 end) as Q3, sum(case when DATEPART(q, dDate)=4 then...
You need to require the driver jar file manually before calling Sequel.connect: require 'path/to/sqljdbc4.jar'. This is true for all Sequel jdbc subadapters where there isn't a corresponding jdbc-* gem wrapping the jar.
javascript,ruby,database,search,sequel
PART 1 You create a name attribute within the <input/> field. So it would look something like this: <input name="search" type="text" placeholder="Search..."/> The most basic way of submitting this input is with an input field where the type=sumbit <input type="submit" value="Search"/> PART 2 It doesn't matter what you call the...
ruby,model-associations,sequel,padrino
I'm not sure if that is what you want, but as you can see in the documentation, the :orders table should contain a foreign key to :users: Sequel.migration do change do create_table :orders do primary_key :id foreign_key :user_id, :users #no stuff yet end end end ...
Yes, it is possible. The method Dataset#columns returns a list of columns. This result can be used to be checked with include? Full example: Sequel.migration do change do table_list = [:table1, :table2, :table3] table_list.each do |t| if ! self[t].columns.include?(:specific_column) alter_table(t) do add_column :specific_column, type: String end end end end end...
mysql,ruby,sequel,on-duplicate-key
It is possible to cause Sequel to execute a function on the RDBMS using the Sequel.function() method To execute MySQL's native LAST_INSERT_ID() and pass the column id as its argument, pass the column name as a symbol as the second argument: Sequel.function(:last_insert_id, :id) The Dataset#on_duplicate_key_update method accepts a hash of...
In the other post you are mentioning, if you look at the answer with the where exists clause you would see that in this clause a join was made between the table in your where exists clause and at least one of the tables in your main join - which...
database,sqlite3,rubygems,sinatra,sequel
If you were doing this professionally, you'd split the app into layers. Inside the routes you'd be in the business or logic layer, and then you'd hand off data requests to the database layer. The database layer would likely be handled by and ORM (like Sequel, Datamapper, or ActiveRecord etc)...
It looks like this might be what you need: http://sequel.jeremyevans.net/rdoc-adapters/classes/Sequel/MySQL.html specifically, calling Sequel::MySQL.convert_tinyint_to_bool = false somewhere in your initialisation code....
Your dataset.each{|r| p r.values} returns not array, it prints them. To get an array with array you could use: DB[:yourtab].all.map{|v|v.values} A more complete example: require 'sequel' DB = Sequel.sqlite DB.create_table(:tab1){ primary_key :id field :a, :type => :nvarchar, :size => 10 field :b, :type => :nvarchar, :size => 10 } DB[:tab1].insert(:a...
I moved the code: RSpec.configure do |config| config.include RspecSequel::Matchers #...other config.. end from spec_helper.rb to rails_helper.rb It's working now....
You've got a typo in your table creation code: DB.create_table :invitations do primay_key :id # <= should be primary_key I get the same error as you do when I introduce this typo into my code. ...
If I understand the Sequel documentation correctly, using Sstring#lit or Sequel.lit should turn a Ruby string into a literal string and bypass the automatic escaping mechanism; therefore, this should work (untested): @values='stuff1\'','stuff2\''.lit db.fetch("query...where IN (?)", "#{@values}") The usual caveats when working with raw SQL strings (SQL injection attacks, inefficient SQL...
ruby,caching,dataset,sinatra,sequel
Memcached or Redis (using LRU) would likely be appropriate solutions for what you are describing. The Ruby Dalli gem makes it pretty easy to get started with memcached. You can find it at https://github.com/mperham/dalli. On the Github page you will see the following basic example require 'dalli' options = {...
I found my answer for the two specific questions I was asking: We don't need to require sequel in the file that calls the class which implements the Model from Sequel. We don't need to connect to the DB in this same file. The DB is called in the class...
The can't convert String into Integer (TypeError) error is because $svc_details is an array i.e. a list of entries where you use a numeric index to select the one you want but you're trying to use a string "credentials" as an index for the array. If you look at your...