Questions tagged [sequel]

Sequel is a database toolkit for the Ruby programming language that provides abstractions over many SQL RDBMS.

Sequel is a "Database Toolkit for Ruby" that:

  • ...provides thread safety, connection pooling and a concise DSL for constructing SQL queries and table schemas.

  • ...includes a comprehensive ORM layer for mapping records to Ruby objects and handling associated records.

  • ...supports advanced database features such as prepared statements, bound variables, stored procedures, savepoints, two-phase commit, transaction isolation, master/slave configurations, and database sharding.

  • ...has adapters for ADO, Amalgalite, DataObjects, DB2, DBI, Firebird, Informix, JDBC, MySQL, Mysql2, ODBC, OpenBase, Oracle, PostgreSQL, SQLite3, and Swift.

See the documentation for a list of guides, examples, tutorials, and other reference material.

Sequel is currently maintained and primarily developed by Jeremy Evans.

735 questions
231
votes
8 answers

How to round an average to 2 decimal places in PostgreSQL?

I am using PostgreSQL via the Ruby gem 'sequel'. I'm trying to round to two decimal places. Here's my code: SELECT ROUND(AVG(some_column),2) FROM table I get the following error: PG::Error: ERROR: function round(double precision, integer)…
user1626730
  • 2,843
  • 5
  • 17
  • 24
40
votes
5 answers

Encoding::UndefinedConversionError

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,…
martriay
  • 5,142
  • 3
  • 23
  • 36
21
votes
6 answers

When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying

A colleague of mine is currently designing SQL queries like the one below to produce reports, which are displayed in excel files through an external data query. At present, only reporting processes on the DB are required (no CRUD operations). I am…
user251732
  • 215
  • 2
  • 6
20
votes
5 answers

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

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…
mb14
  • 20,914
  • 4
  • 54
  • 97
19
votes
2 answers

How to run raw SQL queries with Sequel

I am not clear yet on the proper way to run raw SQL queries with Sequel. Currently I am trying this: DB.fetch("SELECT * FROM zone WHERE dialcode = '#{@dialcode}' LIMIT 1") do |row| @zonename = row end How can I can run the queries as raw SQL then…
veccy
  • 855
  • 3
  • 11
  • 20
16
votes
1 answer

Is there a way to see the raw SQL that a Sequel expression will generate?

Say I have a Sequel expression like: db.select(:id).from(:some_table).where(:foo => 5) Is there a way to get the SQL string that this will generate (i.e. "SELECT id FROM some_table WHERE foo = 5")? I notice that calling inspect or to_s on the…
Matt Zukowski
  • 4,080
  • 4
  • 35
  • 38
14
votes
5 answers

Slicing params hash for specific values

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 } #…
Phrogz
  • 271,922
  • 98
  • 616
  • 693
13
votes
4 answers

How to update or insert on Sequel dataset?

I just started using Sequel in a really small Sinatra app. Since I've got only one DB table, I don't need to use models. I want to update a record if it exists or insert a new record if it does not. I came up with the following solution: rec =…
nooga
  • 530
  • 1
  • 6
  • 19
13
votes
2 answers

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

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…
redka
  • 309
  • 1
  • 11
12
votes
2 answers

Sequel joining tables but I have overlapping column names. How do I alias these column names?

Here is my code for joining two tables: DB.from(:sources).join(:payloads, :source_id => :id) The table names are :sources, :payloads. The problem is that there is an :id column in payloads which overwrites the :id column in :sources. I need to use…
Jwan622
  • 8,910
  • 11
  • 56
  • 125
12
votes
3 answers

How do I test for non-null in Ruby::Sequel?

I'm looking to do something like User.select(...).where(:name != nil) without writing something like User.select(...).to_a.find_all {|user| user.name} I can select for null values, but not for non-null. Is there a trick, or outside Sequel's…
Eric
  • 1,832
  • 2
  • 17
  • 27
11
votes
1 answer

How do I set Ruby Sequel logging to the DEBUG level?

The default Ruby Sequel behaviour is to log all DB queries at the INFO level (unlike ActiveRecord which logs at the DEBUG level). How do I change this?
NatGordon
  • 916
  • 2
  • 10
  • 17
11
votes
1 answer

Defining Sequel models before connecting

In my (non-Rails) app, I'm trying to define a Sequel model: class Foo < Sequel::Model end When I run my app, I'm getting the error: No database associated with Sequel::Model: have you called Sequel.connect or Sequel::Model.db= ?…
Lynn
  • 1,013
  • 15
  • 28
10
votes
4 answers

how do I create a database with sequel

I've read all sequel's docs, but I could not find a way to create a database, assuming that I can do that. I'm running a rake task as such: require 'rubygems' require 'bundler/setup' require 'pg' require 'sequel' require 'yaml' require…
Roland
  • 8,104
  • 16
  • 74
  • 120
9
votes
2 answers

How to write this better? Ruby Sequel chaining OR

In SQL it should look like this: SELECT * FROM `categories_description_old` WHERE ((`categories_description` = '') OR (`categories_name` = '') OR (`categories_heading_title` = '')) My (ugly) solution: conditions = [:categories_name,…
ipsum
  • 982
  • 6
  • 16
1
2 3
48 49