Created
November 22, 2021 09:48
-
-
Save zw963/8eb9d3db1143e4ca1ae4ec0bbba0ab28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
begin | |
require "bundler/inline" | |
rescue LoadError => e | |
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" | |
raise e | |
end | |
gemfile(true) do | |
source "https://rubygems.org" | |
gem 'sequel_pg', require: 'sequel' | |
gem 'pg' | |
gem 'awesome_print' | |
end | |
system("sudo -u postgres dropdb --if-exists check_sequel_db") | |
system("sudo -u postgres createdb check_sequel_db") | |
DB_URL="postgres://postgres:postgres@localhost:5432/check_sequel_db" | |
DB = Sequel.connect(DB_URL) | |
DB.create_table(:investing_latest_news, :ignore_index_errors=>true) do | |
primary_key :id | |
String :title, :text=>true, :null=>false | |
end | |
DB.run "CREATE TEXT SEARCH CONFIGURATION public.pg ( COPY = pg_catalog.simple );" | |
DB.run <<'HEREDOC' | |
ALTER TABLE investing_latest_news | |
ADD COLUMN textsearchable_index_col tsvector GENERATED ALWAYS | |
AS | |
( | |
to_tsvector( | |
'pg', | |
coalesce(title, '') | |
) | |
) | |
STORED; | |
HEREDOC | |
DB.run 'CREATE INDEX investing_latest_news_textsearch_idx_index ON investing_latest_news USING GIN (textsearchable_index_col);' | |
class InvestingLatestNews < Sequel::Model | |
end | |
InvestingLatestNews.create( | |
title: 'Top 5 Things to Watch in Markets in the Week Ahead, [email protected]', | |
) | |
ap InvestingLatestNews.all | |
# [ | |
# [0] #<InvestingLatestNews:0x00005616ae83c190> { | |
# :id => 1, | |
# :textsearchable_index_col => "'5':2 'ahead':11 '[email protected]':12 'in':6,8 'markets':7 'the':9 'things':3 'to':4 'top':1 'watch':5 'week':10", | |
# :title => "Top 5 Things to Watch in Markets in the Week Ahead, [email protected]" | |
# } | |
# ] | |
DB.run('ALTER TEXT SEARCH CONFIGURATION pg DROP MAPPING FOR email') | |
DB.run(Sequel.lit("update investing_latest_news set title=title")) | |
ap InvestingLatestNews.all | |
# [ | |
# [0] #<InvestingLatestNews:0x00005616ae914fb8> { | |
# :id => 1, | |
# :textsearchable_index_col => "'5':2 'ahead':11 'in':6,8 'markets':7 'the':9 'things':3 'to':4 'top':1 'watch':5 'week':10", | |
# :title => "Top 5 Things to Watch in Markets in the Week Ahead, [email protected]" | |
# } | |
# ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment