Skip to content

Instantly share code, notes, and snippets.

@itsNikolay
Created February 14, 2021 15:13
Show Gist options
  • Save itsNikolay/c84fcdcfbc2c00a05540cdf505f69da0 to your computer and use it in GitHub Desktop.
Save itsNikolay/c84fcdcfbc2c00a05540cdf505f69da0 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem 'rails', '5.2.4.5'
gem 'sqlite3'
end
require "active_record"
module Erp
module Packing
module Session
class ZonePicker < ActiveRecord::Base
establish_connection adapter: 'sqlite3', database: 'foobar.db'
connection.create_table table_name, force: true do |t|
t.datetime :started_at
t.datetime :logged_out_at
t.bigint :round_id
end
scope :active, -> { not_logged_out.where('started_at > ?', Time.current.beginning_of_day) }
scope :not_logged_out, -> { where('logged_out_at IS NULL') }
end
end
end
end
# > bundle exec ruby app.rb
# "SELECT \"zone_pickers\".*
# FROM \"zone_pickers\"
# WHERE \"zone_pickers\".\"round_id\" = 3084
# AND (logged_out_at IS NULL)
# AND (started_at > '2021-02-13 21:00:00')"
p Erp::Packing::Session::ZonePicker.where(round_id: 3084).active.to_sql
# "SELECT \"zone_pickers\".*
# FROM \"zone_pickers\"
# WHERE (logged_out_at IS NULL)
# AND (started_at > '2021-02-13 21:00:00')
# AND \"zone_pickers\".\"round_id\" = 3084"
p Erp::Packing::Session::ZonePicker.active.where(round_id: 3084).to_sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment