Creates a sequence with name “name”. Drops it before if it exists
# File vendor/plugins/ubiquo_core/lib/ubiquo/adapters/postgres.rb, line 10
10: def create_sequence(name)
11: drop_sequence(name)
12: self.execute("CREATE SEQUENCE %s;" % name)
13: end
Drops a sequence with name “name” if exists
# File vendor/plugins/ubiquo_core/lib/ubiquo/adapters/postgres.rb, line 16
16: def drop_sequence(name)
17: if(list_sequences("").include?(name.to_s))
18: self.execute("DROP SEQUENCE %s;" % name)
19: end
20: end
Returns an array containing a list of the existing sequences that start with the given string
# File vendor/plugins/ubiquo_core/lib/ubiquo/adapters/postgres.rb, line 23
23: def list_sequences(starts_with)
24: self.execute("SELECT c.relname AS sequencename FROM pg_class c WHERE (c.relkind = 'S' and c.relname ILIKE E'#{starts_with}%');").entries.map { |result| result['sequencename'] }
25: end
Returns the next value for the sequence “name“
# File vendor/plugins/ubiquo_core/lib/ubiquo/adapters/postgres.rb, line 28
28: def next_val_sequence(name)
29: self.execute("SELECT nextval('%s');" % name).entries.first['nextval'].to_i
30: end
Reset a sequence so that it will return the specified value as the next one If next_value is not specified, the sequence will be reset to the “most appropiate value”, considering the values of existing records using this sequence
# File vendor/plugins/ubiquo_core/lib/ubiquo/adapters/postgres.rb, line 35
35: def reset_sequence_value(name, next_value = nil)
36: table, field = name.split('_$_')
37: unless next_value
38: next_value = self.execute('SELECT MAX(%s) as max FROM %s' % [field, table]).entries.first['max'].to_i + 1
39: end
40: self.execute("SELECT setval('%s', %s, false);" % [name, next_value])
41: end
Disabled; run with $DEBUG to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.