Module: Sequel::Sequence::Database

Included in:
Database
Defined in:
lib/sequel/sequence/database.rb,
lib/sequel/sequence/database/sqlite.rb,
lib/sequel/sequence/database/postgresql.rb,
lib/sequel/sequence/database/server/mysql.rb,
lib/sequel/sequence/database/server/mariadb.rb

Defined Under Namespace

Modules: PostgreSQL, SQLite, Server

Constant Summary collapse

DANGER_OPT_ID =
"Warning! The new sequence ID can't be less than the current one."
DANGER_OPT_INCREMENT =
'Warning! Increments greater than 1 are not supported.'
IF_EXISTS =
'IF EXISTS'
IF_NOT_EXISTS =
'IF NOT EXISTS'
SEQUENCE_COMMENT =
'created by sequel-sequence'

Instance Method Summary collapse

Instance Method Details

#build_exists_condition(option) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/sequel/sequence/database.rb', line 69

def build_exists_condition(option)
  case option
  when true
    IF_EXISTS
  when false
    IF_NOT_EXISTS
  end
end

#check_options(params) ⇒ Object



12
13
14
15
# File 'lib/sequel/sequence/database.rb', line 12

def check_options(params)
  log_info DANGER_OPT_INCREMENT if params[:increment] && params[:increment] != 1
  log_info DANGER_OPT_INCREMENT if params[:step] && params[:step] != 1
end

#check_sequencesObject

Raises:

  • (Sequel::MethodNotAllowed)


21
22
23
# File 'lib/sequel/sequence/database.rb', line 21

def check_sequences
  raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
end

#create_sequence(_name, _options = {}) ⇒ Object

Raises:

  • (Sequel::MethodNotAllowed)


25
26
27
# File 'lib/sequel/sequence/database.rb', line 25

def create_sequence(_name, _options = {})
  raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
end

#create_sequence!(name, options = nil) ⇒ Object



89
90
91
92
# File 'lib/sequel/sequence/database.rb', line 89

def create_sequence!(name, options = nil)
  drop_sequence(name, if_exists: true)
  create_sequence(name, options)
end

#currval(_name) ⇒ Object Also known as: lastval

for Postgres

Raises:

  • (Sequel::MethodNotAllowed)


58
59
60
# File 'lib/sequel/sequence/database.rb', line 58

def currval(_name)
  raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
end

#custom_sequence?(_sequence_name) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (Sequel::MethodNotAllowed)


17
18
19
# File 'lib/sequel/sequence/database.rb', line 17

def custom_sequence?(_sequence_name)
  raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
end

#delete_to_currval(_name) ⇒ Object

Raises:

  • (Sequel::MethodNotAllowed)


78
79
80
# File 'lib/sequel/sequence/database.rb', line 78

def delete_to_currval(_name)
  raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
end

#drop_sequence(_name, _options = {}) ⇒ Object

Raises:

  • (Sequel::MethodNotAllowed)


29
30
31
# File 'lib/sequel/sequence/database.rb', line 29

def drop_sequence(_name, _options = {})
  raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
end

#drop_sequence?(*names) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
85
86
87
# File 'lib/sequel/sequence/database.rb', line 82

def drop_sequence?(*names)
  names.each do |n|
    drop_sequence(n, if_exists: true)
  end
  false
end

#nextval(_name) ⇒ Object

Raises:

  • (Sequel::MethodNotAllowed)


53
54
55
# File 'lib/sequel/sequence/database.rb', line 53

def nextval(_name)
  raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
end

#nextval_with_label(_name, _num_label = 0) ⇒ Object

Raises:

  • (Sequel::MethodNotAllowed)


49
50
51
# File 'lib/sequel/sequence/database.rb', line 49

def nextval_with_label(_name, _num_label = 0)
  raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
end

#quote(name) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/sequel/sequence/database.rb', line 41

def quote(name)
  unless respond_to?(:quote_sequence_name, false)
    raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
  end

  name.to_s.split('.', 2).map { |part| quote_sequence_name(part) }.join('.')
end

#quote_name(name) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/sequel/sequence/database.rb', line 33

def quote_name(name)
  unless respond_to?(:quote_column_name, false)
    raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
  end

  name.to_s.split('.', 2).map { |part| quote_column_name(part) }.join('.')
end

#setval(_name, _value) ⇒ Object

Raises:

  • (Sequel::MethodNotAllowed)


65
66
67
# File 'lib/sequel/sequence/database.rb', line 65

def setval(_name, _value)
  raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
end