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.

780 questions
3
votes
1 answer

How to sanitize raw SQL in a Ruby script

I'm trying to write a script that connects with a database using Sequel. If I have a SQL query like this: record_values = csv_row.to_h.values.join(', ') sql_query = "INSERT INTO table (#{ COLUMN_NAMES.join(', ') }) VALUES (#{ record_values })" and…
Henry Yang
  • 2,283
  • 3
  • 21
  • 38
3
votes
1 answer

rake db:schema:dump and rake db:schema:load equivalent in Sequel

I tried following through the source code and the docs, but after a lost morning I give up: at the same time it's as if not enough assumptions are made in the SchemaDumper and at the same time there's no SchemaLoader and following through the sequel…
bbozo
  • 7,075
  • 3
  • 30
  • 56
3
votes
1 answer

How to avoid duplicate field name in query result

I am developing a padrino web application. I have two tables: User table: Has id, name, address fields Post table: Has id, user_id, content If I join them, User.join(:posts, user_id:, :id) they return two fields with the same name id: id name…
Nomura Nori
  • 4,689
  • 8
  • 47
  • 85
3
votes
1 answer

heroku db:push error uninitialized constant Sequel::Postgres::PGError

I have a problem running the heroku db:pull and db:push commands. My app is running Rails 3 on the bamboo-ree-1.8.7 stack. I am new to Sequel and am not sure what the script is complaining about. $heroku db:push Loaded Taps v0.3.14 Auto-detected…
sergiomb
  • 51
  • 1
  • 3
3
votes
1 answer

How to using json fields inside where statement in Sequel?

I have a table transactions id | bigint | NOT NULL DEFAULT nextval('transactions_id_seq'::regclass) transaction_id | bigint | NOT NULL middleware_id | text | opname …
Dimitri
  • 623
  • 7
  • 14
3
votes
1 answer

Ruby Sequel gem: update a row column with a value from another row column that I know the Id

How to write this using the Sequel gem? : update table set col = (select col from table where id = :x) where id = :y I have the record with id=:y but I want to avoid retrieving the record with id(:x) and then doing the update. Just one step! Do I…
MegaTux
  • 1,591
  • 21
  • 26
3
votes
1 answer

How to get single result as an array rather than a Model in Sequel ORM

I am working on a simple application using Roda Ruby gem and Sequel. I want Sequel to return a single result as a array rather than a Model object type. When there is more than one item, it returns an array but when there's only one, it returns a…
B A
  • 1,089
  • 2
  • 14
  • 24
3
votes
1 answer

How to use Sequel with PostGIS

I am using the Sequel gem to access multiple postgres databases. The databases partially use the PostGIS extension. There is a postgis adapter for ActiveRecord, but I haven't found one for Sequel. So my current solution is to use raw SQL to query…
LeoR
  • 666
  • 1
  • 6
  • 20
3
votes
1 answer

In SQL, how can I select a modified column?

I am trying to do this using SQL in Ruby: SELECT number*2 FROM dictionary; I can use .select(:number) to get the number columns "as is", but I have no idea how to return them modified. I tried this (which obviously didn't…
A.V. Arno
  • 513
  • 2
  • 5
  • 12
3
votes
2 answers

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

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 category, subcategory and brand and the corresponding columns and rows in the original…
bcsantos
  • 2,635
  • 5
  • 21
  • 22
3
votes
1 answer

Database abstraction/adapters for ruby

What are the database abstractions/adapters you are using in Ruby? I am mainly interested in data oriented features, not in those with object mapping (like active record or data mapper). I am currently using Sequel. Are there any other options? I…
Stiivi
  • 2,077
  • 2
  • 16
  • 27
3
votes
0 answers

What's the state-of-the-art for pagination with Sequel and Rails 4?

I have a Rails-API app using Sequel which needs pagination. I've come across a few options but have ran into problems with each of them. kaminari looks great, but appears to have no Sequel support. will_paginate appears to have Sequel support, but…
Schwern
  • 153,029
  • 25
  • 195
  • 336
3
votes
2 answers

Is there a last_insert_id method for Sequel?

After an insert, I need to know the ID from the row, how can I do that?
xaver23
  • 1,301
  • 3
  • 12
  • 14
3
votes
1 answer

Sequel eager load some associations of single ORM object

I am building the data model for a small application, and would like to take advantage of eager loading in some methods - i.e. those where I know in advance that certain associations are going to get used. I have read the Sequel::Model::Association…
Neil Slater
  • 26,512
  • 6
  • 76
  • 94
3
votes
4 answers

Multiple aggregate queries using the sequel gem

Is it possible to use sequel to execute a query like this: select (select count(*) from users where blah = 'blah') as "users", (select count(*) from contacts where blah = 'blah') as "contacts" I know I can execute these queries one a time…
dagda1
  • 26,856
  • 59
  • 237
  • 450