module Sequel::Fdbsql::DatasetMethods

Instance methods for datasets that connect to the FoundationDB SQL Layer.

Public Instance Methods

complex_expression_sql_append(sql, op, args) click to toggle source

Emulate the bitwise operators.

Calls superclass method
# File lib/sequel/adapters/shared/fdbsql.rb, line 426
def complex_expression_sql_append(sql, op, args)
  case op
  when :&, :|, :^, :<<, :>>, :'B~'
    complex_expression_emulate_append(sql, op, args)
  # REGEXP_OPERATORS = [:~, :'!~', :'~*', :'!~*']
  when :'~'
    function_sql_append(sql, SQL::Function.new(:REGEX, args.at(0), args.at(1)))
  when :'!~'
    sql << Sequel::Dataset::NOT_SPACE
    function_sql_append(sql, SQL::Function.new(:REGEX, args.at(0), args.at(1)))
  when :'~*'
    function_sql_append(sql, SQL::Function.new(:IREGEX, args.at(0), args.at(1)))
  when :'!~*'
    sql << Sequel::Dataset::NOT_SPACE
    function_sql_append(sql, SQL::Function.new(:IREGEX, args.at(0), args.at(1)))
  else
    super
  end
end
insert(*values) click to toggle source

Insert given values into the database.

Calls superclass method
# File lib/sequel/adapters/shared/fdbsql.rb, line 447
def insert(*values)
  if @opts[:returning]
    # Already know which columns to return, let the standard code handle it
    super
  elsif @opts[:sql] || @opts[:disable_insert_returning]
    # Raw SQL used or RETURNING disabled, just use the default behavior
    # and return nil since sequence is not known.
    super
    nil
  else
    # Force the use of RETURNING with the primary key value,
    # unless it has been disabled.
    returning(*insert_pk).insert(*values){|r| return r.values.first}
  end
end
insert_select(*values) click to toggle source

Insert a record returning the record inserted. Always returns nil without inserting a query if disable_insert_returning is used.

# File lib/sequel/adapters/shared/fdbsql.rb, line 465
def insert_select(*values)
  unless @opts[:disable_insert_returning]
    ds = opts[:returning] ? self : returning
    ds.insert(*values){|r| return r}
  end
end
insert_select_sql(*values) click to toggle source

The SQL to use for an #insert_select, adds a RETURNING clause to the insert unless the RETURNING clause is already present.

# File lib/sequel/adapters/shared/fdbsql.rb, line 474
def insert_select_sql(*values)
  ds = opts[:returning] ? self : returning
  ds.insert_sql(*values)
end
supports_quoted_function_names?() click to toggle source

FDBSQL supports quoted function names

# File lib/sequel/adapters/shared/fdbsql.rb, line 495
def supports_quoted_function_names?
  true
end
supports_regexp?() click to toggle source

FDBSQL has functions to support regular expression pattern matching.

# File lib/sequel/adapters/shared/fdbsql.rb, line 480
def supports_regexp?
  true
end
supports_returning?(type) click to toggle source

Returning is always supported.

# File lib/sequel/adapters/shared/fdbsql.rb, line 485
def supports_returning?(type)
  true
end
supports_timestamp_usecs?() click to toggle source

FDBSQL truncates all seconds

# File lib/sequel/adapters/shared/fdbsql.rb, line 490
def supports_timestamp_usecs?
  false
end

Private Instance Methods

delete_using_sql(sql) click to toggle source

Use USING to specify additional tables in a delete query

# File lib/sequel/adapters/shared/fdbsql.rb, line 502
def delete_using_sql(sql)
  join_from_sql(:USING, sql)
end
insert_pk() click to toggle source

Return the primary key to use for RETURNING in an INSERT statement

# File lib/sequel/adapters/shared/fdbsql.rb, line 507
def insert_pk
  if (f = opts[:from]) && !f.empty?
    case t = f.first
    when Symbol, String, SQL::Identifier, SQL::QualifiedIdentifier
      if pk = db.primary_key(t)
        pk
      end
    end
  end
end
join_from_sql(type, sql) click to toggle source

For multiple table support, PostgreSQL requires at least two from tables, with joins allowed.

# File lib/sequel/adapters/shared/fdbsql.rb, line 520
def join_from_sql(type, sql)
  if(from = @opts[:from][1..-1]).empty?
    raise(Error, 'Need multiple FROM tables if updating/deleting a dataset with JOINs') if @opts[:join]
  else
    sql << SPACE << type.to_s << SPACE
    source_list_append(sql, from)
    select_join_sql(sql)
  end
end
literal_blob_append(sql, v) click to toggle source

FDBSQL uses a preceding x for hex escaping strings

# File lib/sequel/adapters/shared/fdbsql.rb, line 531
def literal_blob_append(sql, v)
  if v.empty?
    sql << "''"
  else
    sql << "x'#{v.unpack('H*').first}'"
  end
end
select_lock_sql(sql) click to toggle source

fdbsql does not support FOR UPDATE, because it's unnecessary with the transaction model

Calls superclass method
# File lib/sequel/adapters/shared/fdbsql.rb, line 540
def select_lock_sql(sql)
  @opts[:lock] == :update ? sql : super
end
update_from_sql(sql) click to toggle source

Use FROM to specify additional tables in an update query

# File lib/sequel/adapters/shared/fdbsql.rb, line 545
def update_from_sql(sql)
  join_from_sql(:FROM, sql)
end