Menu
  • HOME
  • TAGS

Set Integer To Zerofill In Sequel Migration (Ruby ORM)

ruby,orm,sequel,padrino

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' ...

how can I do a full_text_search, using sequel ORM, with 3 parameters?

ruby,postgresql,sequel

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 ...

How to get data from other tables using Sequel

ruby,sinatra,sequel

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:...

Using after_commit transaction hook in Ruby's Sequel

ruby,transactions,sequel

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.

SQL IN operator, separate input values at commas

sql,ruby,sequel

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]...

Ruby getting value from key value pair gives key and value in one string

ruby,sequel

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 # =>...

How to save a hash to a Sequel DB?

ruby,database,csv,hash,sequel

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...

Specify a foreign key in Sequel model

mysql,ruby,sequel,sequel-gem

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)...

How to use enum on Sequel Rails?

ruby-on-rails,sequel

The functionality you're looking for is provided by sequel enum gem. Checkout the README for implementation details. https://github.com/planas/sequel_enum...

strange message sh:line 1 trace xcode-select when running a ruby program

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...

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

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: Outputting Sequel model associations

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) ...

quote value manually before passing to database

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 = '''' ...

Sequel gem: Create tables based on schema provided at runtime

ruby,gem,sequel

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...

In SQL, how can I select a modified column?

sql,ruby,sqlite,sequel

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") ...

Displaying information from a SQL DB into an ERB webpage

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,...

Sequel: exclude records that do not have associations

ruby,sinatra,sequel

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...

ruby sequel gem - how to query arrays with the pg_array extension

ruby,postgresql,sequel

Use the pg_array_ops extension: Sequel.extension :pg_array_ops Email.where(Sequel.pg_array_op(:references).contains('[email protected]')) ...

update column on join table

mysql,ruby,sequel

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"}...

Can Sequel Create And Query Temp Tables

sequel

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. ...

Sequel Sinatra Post Database params

ruby,sqlite3,sinatra,sequel

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...

Ruby: Outputting Sequel schema with associations

ruby,postgresql-9.2,sequel

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.

Quarterly totals using loop in SQL server

sql-server,sequel

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...

using sequel jdbc in ruby to connect to microsoft sql server 2012 - running into error com.microsoft.sqlserver.jdbc.SQLServerDriver not loaded

ruby,sql-server,jdbc,sequel

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.

Creating a search function to search a Sequel Databse using a 'GET' method

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...

How to add stuff I associated to migrations?

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 ...

Sequel migration - only add column if table does not have it yet

ruby,migration,sequel

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...

Can Sequel be forced to always return autoincrement id with ON DUPLICATE KEY UPDATE?

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...

Can anyone explain why this first SQL query gives 0 when this second query gives me results

mysql,sql,sequel

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...

How to use the “select * FROM” method for Sequel databases?

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)...

How do I make Sequel treat column as an integer?

ruby,sequel

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....

How to compare the DB.fetch hash output in Sequel ORM with an existing array?

ruby,sequel

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...

Not able to run rspec with Sequel

ruby-on-rails-4,rspec,sequel

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....

Using a model for an association results in no PK error

ruby,sqlite,sequel

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. ...

single quote escape inside double quotes using sequel fetch function in ruby

ruby,sequel

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...

Caching dataset results in Sequel and Sinatra

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 = {...

Questions about require and DB instances

ruby,sequel

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...

Can't Convert String into Integer - Extract Values from Hash within a Hash

mysql,ruby,arrays,json,sequel

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...