/usr/lib/ruby/vendor_ruby/sequel/database/dataset.rb is in ruby-sequel 4.15.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | module Sequel
class Database
# ---------------------
# :section: 3 - Methods that create datasets
# These methods all return instances of this database's dataset class.
# ---------------------
# Returns a dataset for the database. If the first argument is a string,
# the method acts as an alias for Database#fetch, returning a dataset for
# arbitrary SQL, with or without placeholders:
#
# DB['SELECT * FROM items'].all
# DB['SELECT * FROM items WHERE name = ?', my_name].all
#
# Otherwise, acts as an alias for Database#from, setting the primary
# table for the dataset:
#
# DB[:items].sql #=> "SELECT * FROM items"
def [](*args)
args.first.is_a?(String) ? fetch(*args) : from(*args)
end
# Returns a blank dataset for this database.
#
# DB.dataset # SELECT *
# DB.dataset.from(:items) # SELECT * FROM items
def dataset
@dataset_class.new(self)
end
# Fetches records for an arbitrary SQL statement. If a block is given,
# it is used to iterate over the records:
#
# DB.fetch('SELECT * FROM items'){|r| p r}
#
# The +fetch+ method returns a dataset instance:
#
# DB.fetch('SELECT * FROM items').all
#
# +fetch+ can also perform parameterized queries for protection against SQL
# injection:
#
# DB.fetch('SELECT * FROM items WHERE name = ?', my_name).all
def fetch(sql, *args, &block)
ds = @default_dataset.with_sql(sql, *args)
ds.each(&block) if block
ds
end
# Returns a new dataset with the +from+ method invoked. If a block is given,
# it is used as a filter on the dataset.
#
# DB.from(:items) # SELECT * FROM items
# DB.from(:items){id > 2} # SELECT * FROM items WHERE (id > 2)
def from(*args, &block)
ds = @default_dataset.from(*args)
block ? ds.filter(&block) : ds
end
# Returns a new dataset with the select method invoked.
#
# DB.select(1) # SELECT 1
# DB.select{server_version{}} # SELECT server_version()
# DB.select(:id).from(:items) # SELECT id FROM items
def select(*args, &block)
@default_dataset.select(*args, &block)
end
end
end
|