Re: Asynchronous query to ODBC-compliant database, without waiting for results - possible?

2020-01-14 Thread Jeremy Evans
On Tuesday, January 14, 2020 at 10:21:28 AM UTC-8, Rebecca Paz wrote: > > Hello, > > We are interested in using Sequel to interface with Snowflake > , which is ODBC-compliant and can be > connected to as such: > > require 'odbc' > require 'sequel' > db = Sequel.odbc('S

Re: How to handle boolean in literal where clauses with squel 5.28

2020-01-12 Thread Jeremy Evans
On Sunday, January 12, 2020 at 1:53:23 PM UTC-8, Bernhard Weichel wrote: > > for your info, I tried to debug the line in question. rec[:"Nr"] yields a > numerical value. But i have the impression that the where clause only works > with strings, but not with numericals or booleans. > Incorrect, y

Re: How to handle boolean in literal where clauses with squel 5.28

2020-01-12 Thread Jeremy Evans
On Sunday, January 12, 2020 at 2:25:10 AM UTC-8, Bernhard Weichel wrote: > > Hi > > I have an application running with ruby 1.93 and sequel 4.18.0. I have > statements like > > ogdb.projectcategorys.where('Zuordnungssperre = FALSE') > > No we want to upgrade the application to Ruby 2.6 and squel 5

Re: Simple question about joining a table to itself

2020-01-10 Thread Jeremy Evans
On Friday, January 10, 2020 at 12:35:55 PM UTC-8, Todd wrote: > > I'm a Sequel noobie and I either don't understand the DSL correctly and/or > simply missing something that's obvious. I want to do this... > > SELECT nutrient, a.amt + b.amt AS total FROM anatomy a JOIN anatomy b > USING (nutrient)

Re: Select Fields Not Empty (nil)

2020-01-08 Thread Jeremy Evans
On Wednesday, January 8, 2020 at 9:33:55 AM UTC-8, BeeRich33 wrote: > > >> My apologies for correcting you yet again, hence the questions here in > the group meant for such questions: > > DBS[:searches_t]. > where{(exclude(search_phrase: nil))}. > select(:search_phrase, :result_count) > >

Re: Variable into Sequel.cast

2020-01-08 Thread Jeremy Evans
On Wednesday, January 8, 2020 at 8:00:36 AM UTC-8, BeeRich33 wrote: > > My PG syntax has a variable into an interval: > > WHERE creation_date::timestamp::date > (CURRENT_DATE - interval '$1 days' > )::date > That's interesting, it's not something I would expect to work because the placeholder is

Re: Select Specific Fields from Dataset

2020-01-08 Thread Jeremy Evans
On Wednesday, January 8, 2020 at 7:50:42 AM UTC-8, BeeRich33 wrote: > > So why didn't that take a *Sequel.function* approach? > You are now using a cast instead of a function call. You aren't using the date_trunc function, which is what you asked for a few hours ago, which was how to convert:

Re: Select Specific Fields from Dataset

2020-01-08 Thread Jeremy Evans
On Wednesday, January 8, 2020 at 5:15:32 AM UTC-8, BeeRich33 wrote: > > Sorry, here's my original PG syntax: > > res = $c.exec_params( %Q{ SELECT search_phrase, date_trunc('minute', > creation_date), search_type, result_count... > > > select{[:search_phrase, date_trunc('minute', :creation_date), :

Re: Select Specific Fields from Dataset

2020-01-07 Thread Jeremy Evans
On Tuesday, January 7, 2020 at 4:16:44 PM UTC-8, BeeRich33 wrote: > > In a related application: date_trunc (this rounds up) > > select{[:search_phrase, Sequel.function(:date_trunc(:minute, : > creation_date)).as(:creation_date), :search_type, :result_count]}. > > That field is a timestamp, which I

Re: Complex Select

2020-01-07 Thread Jeremy Evans
On Tuesday, January 7, 2020 at 7:01:05 AM UTC-8, BeeRich33 wrote: > > Trying to avoid *fetch* (which isn't working either), I have the > following attempt for sequel: > > SELECT hashtag, (tagcount/1000) AS tagcount > FROM myhashtags > WHERE status = 'new' > AND NOT hashtag = ANY (?

Re: WHERE creation_date::date > (CURRENT_DATE) - interval '30 days'::date

2020-01-06 Thread Jeremy Evans
On Monday, January 6, 2020 at 9:48:07 AM UTC-8, BeeRich33 wrote: > > Any chance I can get some leadership on that statement? It's one *WHERE* > clause I need to use. > > WHERE creation_date::date > (CURRENT_DATE) - interval '30 days'::date > > *:creation_date* is a timestamp field. It's trippi

Re: Select Specific Fields from Dataset

2020-01-06 Thread Jeremy Evans
On Monday, January 6, 2020 at 7:43:16 AM UTC-8, BeeRich33 wrote: > > So that is always based on *:id*? > > Both look great, but the first I need to remember the select syntax with > curly braces and inner array. > That's also a shortcut. Instead of: select{[:country, count(:id)]}. You could do

Re: Select Specific Fields from Dataset

2020-01-06 Thread Jeremy Evans
On Monday, January 6, 2020 at 5:17:10 AM UTC-8, BeeRich33 wrote: > > Hi folks. How do I select three fields from a dataset? > > SELECT country, count(id) FROM "thistable" WHERE ("status" = 'active') > GROUP BY "country" ORDER BY "country" DESC > > > Currently I have: > > puts DBS[:thistable].wher

Re: New to Sequel

2020-01-03 Thread Jeremy Evans
On Friday, January 3, 2020 at 11:57:39 AM UTC-8, BeeRich33 wrote: > > Hi folks. > > I'm migrating to Sequel from using the PG gem, due to the async nature of > some of their calls. I was getting closure on the connections so I thought > I'd ride this train. > > I have some dashboard charts tha

Re: heroku integration instructions: PR addition to docs?

2020-01-02 Thread Jeremy Evans
On Thursday, January 2, 2020 at 2:02:40 PM UTC-8, Ben Koshy wrote: > > Hi Jeremy > I managed to get a hello world up and running on heroku yesterday using > sequel. it's fairly simple -- once you know -- but i suspect that new > comers may give up in frustration and switch back to active record.

Re: Check if index exists?

2020-01-02 Thread Jeremy Evans
On Thursday, January 2, 2020 at 12:26:27 PM UTC-8, John Hogarty - Ho Gi Hung wrote: > > Thank you for the response Jeremy. I was hoping that I had missed > something and there was a convenience method for checking on > existing indexes :) > > I'll use my current code for now with the begin/res

Re: Check if index exists?

2020-01-02 Thread Jeremy Evans
On Thursday, January 2, 2020 at 10:45:31 AM UTC-8, John Hogarty - Ho Gi Hung wrote: > > Howdy all, > > This might be something simple I am missing, but after searching the docs > and github repo for a few hours and not finding an answer, I thought I > would ask here. > > I have some migrations t

Sequel 5.28.0 Released

2020-01-01 Thread Jeremy Evans
Sequel 5.28.0 has been released! = New Features * An any_not_empty extension has been added, for making Dataset#any? without a block be the same as !empty?. This can result in a much faster database query. * An exclude_or_null extension has been added, adding a Dataset#exclude_or_null met

Re: Feature request: create_or_find

2019-12-24 Thread Jeremy Evans
On Tuesday, December 24, 2019 at 8:20:46 AM UTC-8, Illia Kasianenko wrote: > > Hi, > > The hypothetical create_or_find method could be a nice alternative to > transaction { find_or_create ... }. > It is implemented in AR 6 and the concept is well explained in docs: > https://apidock.com/rails/v6

Re: WITH OUTPUT Optimization for MSSQL INSERTs / UPDATEs

2019-12-21 Thread Jeremy Evans
On Saturday, December 21, 2019 at 3:08:07 AM UTC-8, Jurgens du Toit wrote: > > Hey > > When using Sequel on MSSQL, adding any triggers on tables will break any > actions on models / tables that results in a UPDATE or INSERT statement. > This is due to how Sequel formats the INSERT / UPDATE statem

Re: Eager loading of relationships for dynamic dataset

2019-12-21 Thread Jeremy Evans
On Friday, December 20, 2019 at 11:33:21 PM UTC-8, Beth Skurrie wrote: > > Thanks Jeremy. > > The delay almost works. > > DenormalisedOrderLine3.dataset.clone(product_name: "Fish") > => # `product_name`, `customer_id` FROM `orders` LEFT OUTER JOIN (SELECT * FROM > `order_lines` WHERE (`product_nam

Re: Eager loading of relationships for dynamic dataset

2019-12-19 Thread Jeremy Evans
On Thursday, December 19, 2019 at 5:29:46 PM UTC-8, Beth Skurrie wrote: > > Hi, > > Thanks to everyone who works on Sequel or helps answer Sequel questions. > > I have a tricky problem that I'm trying to solve involving dynamic > queries, classes, eager loading, and performance. I've come up with

Re: rails route helper question, and form_with question

2019-12-19 Thread Jeremy Evans
On Thursday, December 19, 2019 at 10:47:51 AM UTC+2, Ben Koshy wrote: > > > I'm getting this error message: > > undefined method `to_model' for # Did you > mean? to_yaml > You probably want to load the active_model plugin if you are using Rails. Unfortunately, not having any recent experience wi

Re: Documenting the mock adapter

2019-12-12 Thread Jeremy Evans
On Thursday, December 12, 2019 at 3:10:46 AM UTC-8, Janko Marohnić wrote: > > Hi Jeremy, > > I've found the Sequel's mock adapter useful in some self-contained scripts > where I didn't need the actual connection. There was a recent Twitter > discussion

Re: Class definitions in Sequel source

2019-12-05 Thread Jeremy Evans
On Thursday, December 5, 2019 at 6:05:25 AM UTC-8, Petr Kaleta wrote: > > Hi everyone, > I've found this in Sequel source > > ( > # Exception class raised when +require_modification+ is set and an > UPDATE or DELETE statement to modify the dataset doesn't > # modify a single row. > NoExistin

Sequel 5.27.0 Released

2019-12-01 Thread Jeremy Evans
Sequel 5.27.0 has been released! = New Features * Sequel::DEFAULT has been added a constant for the DEFAULT expression, useful in inserts and especially updates: DB[:a].where(:id=>1).update(:b=>Sequel::DEFAULT) # UPDATE "a" SET "b" = DEFAULT WHERE "id" = 1 * SQL::Function#filter for f

Re: Newbie Dataset Filter Question

2019-11-20 Thread Jeremy Evans
On Wednesday, November 20, 2019 at 1:21:41 PM UTC-8, Mason Kimble wrote: > > Basically, can I filter a dataset after it goes to the database? > > order_items = OrderItem.dataset.where(order_id: orderId).all (I know this > would query database) > > orders_items_to_match.each { | match_item | >

Re: TinyTDS Adapter unexpectedly uses `varchar` instead of `nvarchar` for migrations

2019-11-19 Thread Jeremy Evans
On Tuesday, November 19, 2019 at 7:47:24 PM UTC-8, Tim Tilberg wrote: > > Tonight I noticed a small detail that surprised me a little bit, and I > wanted to discuss whether it should be changed: > > When doing migrations against SQL Server using the TinyTDS adapter, the > default `String` column

Re: Dataset module methods help

2019-11-19 Thread Jeremy Evans
On Tuesday, November 19, 2019 at 12:31:21 PM UTC-8, Jake wrote: > > I have some dataset_module methods defined within a model class. > > class Example > dataset_module do > def method_a > where(...) // Standard where filter only using this table > end > > def method_b > jo

Sequel 5.26.0 Released

2019-11-01 Thread Jeremy Evans
Sequel 5.26.0 has been released! = New Features * Support for SQL/JSON path expressions has been added to the pg_json_ops extension. These are supported in PostgreSQL 12+. Examples: j = Sequel.pg_json_op(:json_column) j.path_exists('$.foo') # (jsonb_column @? '$.foo') j.path

Re: Why `order` allow array that is not usually working?

2019-10-30 Thread Jeremy Evans
On Wednesday, October 30, 2019 at 3:37:04 AM UTC-7, Adam Aiken wrote: > > I have just found that function `order` in dataset class supports array > that is not always working. > > Sequel[:users].order([ > Sequel[:users][:id] > ]).all # OK > # SQL: SELECT * FROM users ORDER BY (id) > > Sequel

Re: Multi-table DELETE via a USING clause

2019-10-25 Thread Jeremy Evans
On Friday, October 25, 2019 at 3:29:03 PM UTC-7, Nícolas Iensen wrote: > > Thanks for your reply. > > Now considering the two models below: > > class Producer < Sequel::Model > one_to_many :films > > dataset_module do > def fooes > where{name = "foo"} > end > end > end > > clas

Re: How to deal with transient connectivity errors from Azure

2019-10-25 Thread Jeremy Evans
On Thursday, October 24, 2019 at 10:30:40 PM UTC-7, Eugene Lai wrote: > > I have an API server running sinatra/thin/sequel connected to a managed > Postgres database provided by Azure Database for PostgreSQL. > > For background to my problem I refer to this: > https://docs.microsoft.com/en-us/azu

Re: Cache `Database.tables` when `Database.cache_schema`

2019-10-18 Thread Jeremy Evans
On Friday, October 18, 2019 at 11:05:47 AM UTC-7, Alexander Popov wrote: > > Hello. > > I want to check an existence of tables. > > But I don't see a way to make it through cached list by default. > > I see `Database.cache_schema`, which is `true` by default. > > And I see `Database.tables` (from P

Re: Reliable segfault with Sequel/Puma/Postgres/Catalina

2019-10-15 Thread Jeremy Evans
On Monday, October 14, 2019 at 11:28:03 PM UTC-7, Corey Csuhta wrote: > > Hey all: > > I have a reproduceable Ruby segfault when I use Puma, Sequel, and Postgres > together in MacOS Catalina. > > I have this code in my Puma config: > > before_fork do > ::Sequel::DATABASES.each(&:disconnect) > e

Sequel 5.25.0 Released

2019-10-01 Thread Jeremy Evans
Sequel 5.25.0 has been released! = New Features * An association_multi_add_remove plugin has been added. This plugin adds a shortcut for adding or removing multiple associated objects in a single method call: Artist.plugin :association_multi_add_remove Artist.many_to_one :albums

Re: Multiple joins across table with only the first record from a specific table

2019-09-30 Thread Jeremy Evans
On Monday, September 30, 2019 at 7:18:04 AM UTC-7, abhijit wrote: > > Hi, > > I've been breaking my head over this one. > > I have a 'users' table and an 'addresses' table with the foreign key > 'user_id' > I also have a 'claims' table where users make claims with the foreign key > of 'user_id' >

Re: Atomic insert

2019-09-26 Thread Jeremy Evans
On Thursday, September 26, 2019 at 1:57:23 PM UTC-7, Alon wrote: > > What's the best way to implement an atomic insert/update in Rails? A good > analogy for the problem I'm trying to solve is that I have two tables and > I'm running API request and wrap the request with transaction using > Se

Re: TimeStampMigrator with rails engine best practice to update version

2019-09-25 Thread Jeremy Evans
On Wednesday, September 25, 2019 at 5:31:03 AM UTC-7, D-lev wrote: > > It seems that I didn't explain the use case correctly. > > We support a backup and restore of our DB (postgres) via native dump tool. > > V - We do copy migration files from engine to main application. > engine/db/migration/*2

Re: TimeStampMigrator with rails engine best practice to update version

2019-09-24 Thread Jeremy Evans
On Tuesday, September 24, 2019 at 2:22:52 AM UTC-7, D-lev wrote: > > Hi, > We have develop a task to migrate files from db/migration at engine level > to the wrapper. > something activerecord already have: > > https://github.com/rails/rails/blob/16f2cd88e3ee92de341ba30b102e9206be3c68a7/activerecor

Re: ConnectionError: Lost connection to MySQL

2019-09-06 Thread Jeremy Evans
On Friday, September 6, 2019 at 8:24:58 AM UTC-7, Ryan W wrote: > > It happens during all rolling restarts from what I've observed, which is > where we first started seeing it. As load has increased it has started > happening more throughout other times well after restarts, perhaps when > passen

Re: ConnectionError: Lost connection to MySQL

2019-09-06 Thread Jeremy Evans
On Thursday, September 5, 2019 at 11:06:25 PM UTC-7, Ryan W wrote: > > Recently, we began experiencing more of these during rolling restarts and > busy periods. > > Sequel::DatabaseDisconnectError: Mysql2::Error::ConnectionError: Lost > connection to MySQL server during query > Does this error o

Re: Multiple PG Databases using Sequel

2019-09-02 Thread Jeremy Evans
On Monday, September 2, 2019 at 2:49:26 AM UTC-7, D-lev wrote: > > Hi, > There is a mention of "The DB convention" > , and I'm > missing a starting point of using two different database (one for business > logic and the other for auditing)

Sequel 5.24.0 Released

2019-09-01 Thread Jeremy Evans
Sequel 5.24.0 has been released! = New Features * A :cache_file plugin option has been added to the pg_auto_constraint_validations plugin. This option specifies a file to use to cache the metadata the plugin uses, so the plugin does not need to run 5 queries per model at startup to load

Re: What is the better way to manage long list of old migrations?

2019-08-28 Thread Jeremy Evans
On Wednesday, August 28, 2019 at 5:44:29 AM UTC-7, Nicolò Benigni wrote: > > I have a Rails app with 4 years of migrations and everytime I start a new > machine and try to run them all they give ton of errors. > So I usually use rake db:schema:load but would prefer to "squash" togheter > all my

Re: Adding validators like in ValidationHelpers / extending ValidationHelpers

2019-08-20 Thread Jeremy Evans
On Tuesday, August 20, 2019 at 5:51:44 AM UTC-7, Nick Nope wrote: > > I like to add validators the same way as they are in ValidationHelpers. > Since those already sport options like :allow_missing, :allow_nil etc. it > would be nice to build upon that functionality. However the method > validat

Re: Ensure foreign keys are present

2019-08-17 Thread Jeremy Evans
On Saturday, August 17, 2019 at 6:50:02 AM UTC-7, craig buchanan wrote: > > Given a ProductRating class: > > class ProductRating < Sequel::Model > plugin :validation_helpers > > many_to_one :person > many_to_one :product > > def validate > super > validates_presence [:rating] >

Re: IS DISTINCT FROM support

2019-08-15 Thread Jeremy Evans
On Thursday, August 15, 2019 at 8:50:25 AM UTC-7, Yuri Smirnov wrote: > > Hi, I need to generate some SQL that looks like this: > > row(1, 2, null, 3) IS NOT DISTINCT FROM row(1, 2, null, 3) > > Is there some simple way to do that with Sequel? > Sequel currently doesn't have DSL support for "IS NO

Re: JDBC Array datatype handling

2019-08-15 Thread Jeremy Evans
On Thursday, August 15, 2019 at 3:53:45 AM UTC-7, Guy Boertje wrote: > > > Do other drivers use driver-specific array types? > > I'm not sure about the driver-specific bit but I imagine that the driver > designers will use a Java JDBC array type if the DB technology supports > array columns or si

Re: JDBC Array datatype handling

2019-08-14 Thread Jeremy Evans
On Wednesday, August 14, 2019 at 2:23:16 AM UTC-7, Guy Boertje wrote: > > Hi, > > I have a question regarding the generic type conversion for JDBC Array > types. > > The java examples I've seen do a further getArray call on the object > returned by resultset.getArray(column) > > java.sql.Array

Re: FullTextSearch (to_tsquery and to_tsvector in WHERE clause)

2019-08-13 Thread Jeremy Evans
On Tuesday, August 13, 2019 at 1:05:12 PM UTC-7, xura wrote: > > Hi, > > How can I translate this query to Sequel/Ruby? Does Sequel has ability to > handle such queries or do i need to execute raw? > > SELECT * FROM contacts WHERE to_tsvector('English', addresses ->> > 'address') @@ to_tsquery('H

Re: Attribute accessor does not pick data from query when I use as.

2019-08-13 Thread Jeremy Evans
On Tuesday, August 13, 2019 at 1:06:43 AM UTC-7, Sudhanshu Kumar Singh wrote: > > But it is not applying filter on the query when I make dataset out of > query using .fetch(Query) and apply filter like: > `dataset.where(::Sequel.lit("#{column_table_name}.#{column} >= ?", > min_value))` or `datas

Re: Attribute accessor does not pick data from query when I use as.

2019-08-12 Thread Jeremy Evans
On Monday, August 12, 2019 at 8:19:03 AM UTC-7, Sudhanshu Kumar Singh wrote: > > Hi Everyone, > I added this query and added attr_accessor "balance_amount" and > "booking_customer_id" in customers table, my query sets the value on > attribute accessor but I am not able to fetch it from the

Re: Use of qualified identifier as a where clause?

2019-08-12 Thread Jeremy Evans
On Monday, August 12, 2019 at 12:02:00 AM UTC-7, Greg Gilbert wrote: > > Hey, > > Quick question for MySQL: suppose I have a query where I'm doing > associated joins, and I want to query by an id on the original table: > > items = Item.select_all(:items) >> items = items.association_join(:item_det

Re: Create model with unrestricted param setting omits primary keys in insert statement

2019-08-08 Thread Jeremy Evans
On Thursday, August 8, 2019 at 3:03:47 AM UTC-7, Nick Nope wrote: > > Hello there, > > I have an n:m table with two primary keys. In my tests I am populating the > db manually by creating new rows with the a sequel model's create method. > To be able to set primary keys I am unrestricting the mod

Sequel 5.23.0 Released

2019-08-01 Thread Jeremy Evans
Sequel 5.23.0 has been released! = New Features * An insert_conflict plugin has been added for automatically handling constraint conflicts when saving new model instances. It is supported on PostgreSQL 9.5+ and SQLite 3.24.0+. Album.new(name: 'Foo', copies_sold: 1000). insert_conf

Re: dirty plugin and joined columns

2019-07-30 Thread Jeremy Evans
On Tuesday, July 30, 2019 at 1:23:35 PM UTC-7, Jason Landry wrote: > > I have an interesting (well, to me anyway LOL) and perhaps philosophical > issue with the :dirty plug and using a model instance with a join. > > Consider the following overly simplified example: Get the ID of one order > fro

Re: How to add pre-query dataset method calls?

2019-07-24 Thread Jeremy Evans
On Wednesday, July 24, 2019 at 2:14:44 PM UTC-7, Karl He wrote: > > Bit of a weird situation here. > > So I have a dataset that I want to be able to pass around everywhere > treated normally, except that I have a `WHERE > ` and `GROUP BY` I want to always apply to it before any rows are returned.

Re: Table join with attributes

2019-07-21 Thread Jeremy Evans
On Sunday, July 21, 2019 at 3:41:54 PM UTC-7, Matthew Gibbons wrote: > > Okay, so I have this: > > class Team < Sequel::Model > many_to_many :users > > many_to_many(:admins, class: User, :join_table => :teams_users, > :right_key => :user_id) do |ds| > ds.where(Sequel[:teams

Re: Issue with Dataset#count when using having

2019-07-19 Thread Jeremy Evans
On Thursday, July 18, 2019 at 6:48:28 PM UTC-7, Stephen Weil wrote: > > Hello, > > I ran into this issue with Sequel and MariaDB/MySQL, with a query that > uses Dataset#select_append to get some calculated values and then uses > Dataset#having to filter by those calculated fields. This produces a

Re: XYZ is a restricted primary key -> How to set it?

2019-07-17 Thread Jeremy Evans
On Wednesday, July 17, 2019 at 12:08:20 PM UTC-7, Nick Nope wrote: > > Hello there, > > I have a table (user_verifications) which has a non auto-incrementing > primary key (user_id). The PK is an id referencing another table (users) > via foreign key (user_verifications.user_id -> users.user_id).

Re: Is it possible to add a condition to a Sequel Dataset join on condition?

2019-07-09 Thread Jeremy Evans
On Tuesday, July 9, 2019 at 1:14:52 PM UTC-7, marc halperin wrote: > > I need to be able to take a Dataset object and for any join's where both > tables contain a particular column 'x' I want to add to the on condition > '... AND A.x=B.x' (where A and B are the tables already set to be join in >

Re: How bad is it to call #call method of a model to get model instance of a desired class?

2019-07-09 Thread Jeremy Evans
On Tuesday, July 9, 2019 at 5:05:08 AM UTC-7, Artem Kondratev wrote: > > We are using subclassed plugin to have different classes (let's say that > each of them represents bank account type in different countries) with one > underlying table. Bank account types can be identified with a X field in

Re: migration: inserting a value when migrations

2019-07-08 Thread Jeremy Evans
On Sunday, July 7, 2019 at 9:05:13 PM UTC-7, Shunsuke Tamiya wrote: > > Hi Jeremy, > > I know how to insert values that are taken from another table when > migrations. > > Sequel.migration do > up do > create_table(:slot, ignore_index_errors: false) do > String :uuid, size: 45, null:

Re: Problem with tracking changes in jsonb columns

2019-07-07 Thread Jeremy Evans
On Sunday, July 7, 2019 at 4:29:05 AM UTC-7, Юрий Смирнов wrote: > > I understand, but the problem is not with accessing certain keys, but with > tracking changes in my case. The previous_changes method returns the result > that is not valid. I can also can have some symbols somewhere inside valu

Re: Problem with tracking changes in jsonb columns

2019-07-06 Thread Jeremy Evans
On Saturday, July 6, 2019 at 5:01:31 AM UTC-7, Юрий Смирнов wrote: > > I have a model with jsonb column and I use the pg_json extension. Here is > the problem: > > > model.update(x: { a: 1 }) > > > > model.x > => {:a=>1} > > > model.previous_changes > => {:x=>[{"a"=>1}, {:a=>1}]} > > > model.reloa

Re: Subcleasses' methods

2019-07-06 Thread Jeremy Evans
On Saturday, July 6, 2019 at 12:22:52 AM UTC-7, Artem Kondratev wrote: > > You're right. > > How about implicit_subquery then? > > def self.dataset > ds = QUERY['SELECT * FROM bank_accounts where attr IS NULL'] > ds = ds.extension(:implicit_subquery) > ds > end > > The initial result looks li

Re: Possibility of adding `Sequel::Model#with_lock`?

2019-07-06 Thread Jeremy Evans
On Friday, July 5, 2019 at 5:54:43 PM UTC-7, Janko Marohnić wrote: > > Hello, > > Active Record has `ActiveRecord::Base#lock!` method just like Sequel, and > additionally it has `ActiveRecord::Base#with_lock`, which wraps the > `#lock!` in a transaction: > > model.with_lock do > # ... > e

Re: Subcleasses' methods

2019-07-05 Thread Jeremy Evans
On Friday, July 5, 2019 at 12:33:38 PM UTC-7, Artem Kondratev wrote: > > Can be solved by using a before_save hook I suppose. > > class BankAccountSub < BankAccoun > def before_save > self.attr = nil > super > end > end > > As for the first issue - I have yet to research the options, bu

Re: Subcleasses' methods

2019-07-05 Thread Jeremy Evans
On Friday, July 5, 2019 at 7:41:02 AM UTC-7, Artem Kondratev wrote: > > Let's say we have a class > > class BankAccount < Sequel::Model do > plugin :subclasses > > end > > And it's subclass > > class BankAccountSub < BankAccount > end > > If we are going to call it's methods like > > BankAccountS

Re: Using Sequel through Ruby-Java bridge instead of JRuby

2019-07-02 Thread Jeremy Evans
On Tuesday, July 2, 2019 at 3:21:49 AM UTC-7, Clxy wrote: > > We want to access some Databases through JDBC. > But we don't (couldn't) have JRuby enviroment. > So, we are thinking about [Ruby-Java bridge > ](https://github.com/arton/rjb) > > It seems that 『sequel/ada

Sequel 5.22.0 Released

2019-07-01 Thread Jeremy Evans
Sequel 5.22.0 has been released! = New Features * Sequel now supports Ruby 2.7+ startless ranges in filters: DB[:table].where(:column=>(..10)) # SELECT * FROM table WHERE (column <= 10) DB[:table].where(:column=>(...10)) # SELECT * FROM table WHERE (column < 10) It also suppo

Re: Cannot update record using the instance method .save or .save_changes

2019-06-26 Thread Jeremy Evans
On Wednesday, June 26, 2019 at 5:41:15 PM UTC-7, lkfken wrote: > > Hi, > > I have a very simple record > > policy_number = 'P31206' > > > ccsb_group_record = EdiShop::ShopGroupCrosswalk.where(:policynumber => > policy_number).first > # #"P31206", > :group_id=>"M10050", :orig_eff_dt=>2014-

Re: Suggestion: Make the eager_load method defined in associations.rb a Class method instead of a Dataset method.

2019-06-25 Thread Jeremy Evans
On Tuesday, June 25, 2019 at 4:09:36 PM UTC-7, Paul Martinez wrote: > > Occasionally a method will be passed a model, or an array of models, and > access (possibly nested) associations on those models. In certain cases it > may be difficult to update the code that originally fetches those models

Re: ConnectionPool Max Lifetime

2019-06-25 Thread Jeremy Evans
On Tuesday, June 25, 2019 at 2:23:36 PM UTC-7, Stephen Weil wrote: > > For context: I am using Sequel (5.14) on jruby to connect to an AS400 > using jdbc/jt400 and the sequel-jdbc-as400 gem. I know the AS400 adapter > has been deprecated as of Sequel 5.0, but I believe my question pertains > mor

MSSQL's #schema_parse_table does not support linked servers

2019-06-22 Thread Jeremy Evans
Ideally, linked servers can be recognized by the 4 level qualified identifier, and handled transparently. However, that may not be possible or may be too complex to be worth supporting by default, in which case it would be best to support via an extension. Thanks, Jeremy -- You received this

Re: how to use a "variable" for column name when doing update on row

2019-06-20 Thread Jeremy Evans
On Thursday, June 20, 2019 at 2:05:48 PM UTC-7, Grant Schoep wrote: > > I have this module I am using to do updates on a row in a table that is > getting very redundant. I was trying to figure out if I can reduce this by > using some type of variable in place of the column name. > > So for examp

Re: Model instance's associations not updating when instance's foreign key updated

2019-06-14 Thread Jeremy Evans
On Friday, June 14, 2019 at 12:35:19 PM UTC-7, Jake wrote: > > That isn't the exact code I'm using, I was just trying to use a simple > example with something one to one. > > For a more realistic example I have a `user account` model that has a one > to one association with another model to trac

Re: Model instance's associations not updating when instance's foreign key updated

2019-06-14 Thread Jeremy Evans
On Friday, June 14, 2019 at 12:18:57 PM UTC-7, Jake wrote: > > I'm not sure if this is an intended feature or a bug but I couldn't find > any documentation about this. > > ex. > class Person < Sequel::Model > one_to_one :pet, key: :pet_type, primary_key: :pet_type > end > > class Pet < Sequel::Mo

Re: Using single_table_inheritance, created object doesn't return subclass

2019-06-13 Thread Jeremy Evans
On Thursday, June 13, 2019 at 10:23:00 AM UTC-7, Tom wrote: > > Following up the issue I posted here > (Sorry if I should > have directed it here first) > > I'm wondering why the behavior is to return the receiver instead of the > subclass? Cou

Re: invalid query with dataset.empty? raises a Sequel::DatabaseDisconnectError instead of Sequel::DatabaseError

2019-06-11 Thread Jeremy Evans
On Tuesday, June 11, 2019 at 10:26:59 AM UTC-7, Ryan Kingston wrote: > > > If I pass an invalid query to the dataset.empty? method, it raises a > Sequel::DataseDisconnectError. It would be a lot more helpful if it raised > a Sequel::DatabaseError like it does if I call dataset.all > > > EXISTS_

Re: CTE in Sequel

2019-06-11 Thread Jeremy Evans
On Tuesday, June 11, 2019 at 9:38:23 AM UTC-7, lkfken wrote: > Thank you Jeremy. Your example is clear and it works. > > Now what if I need to chain this with another CTE? For example > > WITH C1 AS ( > ... >), > C2 AS ( > > SELECT C1.*, se = ROW_NUMBER() OVER (PARTITION BY [MEMBER_ID], [

Re: CTE in Sequel

2019-06-10 Thread Jeremy Evans
On Monday, June 10, 2019 at 5:19:58 PM UTC-7, lkfken wrote: > > Hi, > > I would like to convert the SQL code below to Sequel. Hopefully, after I > see the conversion, I will have a better understand on how Sequel handle > CROSS APPLY and VALUES and CTE > > WITH C1 AS ( > SELECT >

Re: How best to call a procedure in mssql?

2019-06-07 Thread Jeremy Evans
On Friday, June 7, 2019 at 7:32:16 AM UTC-7, Allan Peda wrote: > > I am finishing a port to of a data load script to sequel, and I just need > to call a procedure. > > It's a procedure we use at my company to normalize/clean a table > (previously which was called via DBI using the ".do" method

Re: Issue with SEQUEL when moved from tinyTDS to JDBC

2019-06-07 Thread Jeremy Evans
On Friday, June 7, 2019 at 5:13:55 AM UTC-7, Rama Musidipalli wrote: > > Good Morning, All. > > Thank you very much, Jeremy. > > I see the execute method of Statement class is returning a boolean > indicating if resultset exists for unknown SQL statement and then can be > fetched using getResultS

Re: Issue with SEQUEL when moved from tinyTDS to JDBC

2019-06-06 Thread Jeremy Evans
On Thursday, June 6, 2019 at 8:31:40 AM UTC-7, Rama Musidipalli wrote: > > Thank you Jeremy. Sure, will go with your recommendation. > > Could you suggest method for running Stored Procedure that run few insert, > updates and then return cursor. > Sequel has some limited support for stored proced

Re: Issue with SEQUEL when moved from tinyTDS to JDBC

2019-06-06 Thread Jeremy Evans
On Thursday, June 6, 2019 at 5:40:33 AM UTC-7, Rama Musidipalli wrote: > > > I am new to Ruby... Please pardon me for any incorrect terminology.. > > > Issue: DB["DELETE..."] ran using tinyTDS is returning empty array whereas > thru JDBC sybase adapter is not returning this empty array thus result

Re: Want to know about `multi_update` ?

2019-06-06 Thread Jeremy Evans
On Thursday, June 6, 2019 at 12:34:54 AM UTC-7, Wayne Chan wrote: > > Hi, > Is there a way to use Sequel to update many row in one query, just like > `multi_insert` insert many row at once. > > Thanks for any help! > UPDATE in SQL can already update multiple rows in one query. By default, witho

Sequel 5.21.0 Released

2019-06-01 Thread Jeremy Evans
Sequel 5.21.0 has been released! = New Features * The pg_json extension now adds a Database#wrap_json_primitives accessor. When set to true, JSON primitive values (string, number, true, false, and null) will be wrapped by delegate Ruby objects instead of using Ruby primitives. This allows

Re: Many to Many Association -> Unique Constraint Violation?

2019-05-31 Thread Jeremy Evans
On Friday, May 31, 2019 at 7:57:59 AM UTC-7, JB wrote: > > Hello, I'm new to Sequel, so please excuse my maybe simple question. > > I want to set up a many to many association. When adding such an > association, it leads to a UNIQUE constraint violation. It seems like I > miss something here. Ma

Re: how to properly create fields and values with OR

2019-05-26 Thread Jeremy Evans
On Sunday, May 26, 2019 at 8:10:45 AM UTC-7, xura wrote: > > I have this hash: > > fields = { > name: 'John', > subject: 'Hello' > } > > > And I send this hash by this: > > Email.where(fields).where(another_condition: 4).all > > It works, however, When I want to add OR I need to explicitly defi

Re: What is the best way of creating GIN INDEX

2019-05-24 Thread Jeremy Evans
On Friday, May 24, 2019 at 10:39:48 AM UTC-7, xura wrote: > > Hi, > > Following is an :gin index for jsonb fields: > > CREATE INDEX index_name > ON public.emails > USING gin > (send_cc, send_bcc, send_to, sender); > > So, in Sequel docs no :Gin mentioned. Is there a better way to do this >

Re: `RcteTree` plugin with `eager_graph`

2019-05-24 Thread Jeremy Evans
On Monday, May 20, 2019 at 12:59:52 PM UTC-7, Jeremy Evans wrote: > > Not a bug in eager_graph, it is just that associations that use CTEs > cannot be graphed. We should probably raise an exception if you try to use > eager_graph, though. I'll try to make that change before

Re: jsonb, LATERAL and DISTINCT query with sequel

2019-05-24 Thread Jeremy Evans
On Friday, May 24, 2019 at 6:22:53 AM UTC-7, xura wrote: > > In fact, query is now like this: > > SELECT DISTINCT ON (jj->>'email') jj->>'email', jj->>'name' , count(*) > over(partition by jj->>'email' ) > from emails > join lateral jsonb_array_elements(send_to) j(jj) on true > ORDER BY jj->>'em

Re: Question about placeholders / binds from arrays of data

2019-05-24 Thread Jeremy Evans
On Friday, May 24, 2019 at 6:48:52 AM UTC-7, Allan Peda wrote: > > Hi, > > I am using Sequel mostly for the convenience of bind variables (with > MSSQL/tiny_tds). > > I see positional binds are possible with a straight SQL call, as in: > > arr = [33, 26, 33] > sth = dbh['insert into mytab(a, b, c)

`RcteTree` plugin with `eager_graph`

2019-05-20 Thread Jeremy Evans
Not a bug in eager_graph, it is just that associations that use CTEs cannot be graphed. We should probably raise an exception if you try to use eager_graph, though. I'll try to make that change before the next release. Thanks, Jeremy -- You received this message because you are subscribed to t

Re: Nonexistent server for `ServerBlock` extension doesn't raise error

2019-05-13 Thread Jeremy Evans
On Monday, May 13, 2019 at 10:23:25 AM UTC-7, Jeremy Evans wrote: > > On Monday, May 13, 2019 at 9:17:39 AM UTC-7, Alexander Popov wrote: >> >> Thank you. >> >> We added: >> >> servers: { read_only: {} } >> >> , as written in the documentation,

Re: Nonexistent server for `ServerBlock` extension doesn't raise error

2019-05-13 Thread Jeremy Evans
On Monday, May 13, 2019 at 9:17:39 AM UTC-7, Alexander Popov wrote: > > Thank you. > > We added: > > servers: { read_only: {} } > > , as written in the documentation, and we're getting: > > ``` > > DB.with_server(:foo) { Artist.all } > NoMethodError: undefined method `[]' for nil:NilClass > from >

Re: Storing JSON primitive types (string, number, bool, null) in a JSONB column using Sequel

2019-05-10 Thread Jeremy Evans
On Tuesday, April 30, 2019 at 8:08:12 AM UTC-7, alexanderfrankel...@gmail.com wrote: > > Ah makes sense. > > Ok. If all primitive types are supported, either adding an option to the > existing pg_json extension or creating a new extension sounds good to me! > I've just pushed a commit to Sequel

Re: TinyTDS, Sequel::Dataset#paged_each, timeout

2019-05-08 Thread Jeremy Evans
On Wednesday, May 8, 2019 at 5:04:34 PM UTC-7, Jonathan Simpson wrote: > > Thanks, Jeremy! > > No, we are not using the same database object. Each source or destination > in these ETL jobs is it's own database object. > > What follows is the backtrace and I've cobbled together a quick/contrived >

<    1   2   3   4   5   6   7   8   9   10   >