Sha256: 280e5f4bc15463d051718f9f3503ab1d3407457e3bfafee3a787c0abbc951558
Contents?: true
Size: 1.22 KB
Versions: 13
Compression:
Stored size: 1.22 KB
Contents
module Sequel class Model # Defines a table schema (see Schema::Generator for more information). # # This is only needed if you want to use the create_table or drop_table # methods. def self.set_schema(name = nil, &block) if name set_dataset(db[name]) end @schema = Schema::Generator.new(db, &block) if @schema.primary_key_name set_primary_key @schema.primary_key_name end end # Returns table schema for direct descendant of Model. def self.schema @schema || ((superclass != Model) && (superclass.schema)) end # Returns name of table. def self.table_name dataset.opts[:from].first end # Returns true if table exists, false otherwise. def self.table_exists? db.table_exists?(table_name) end # Creates table. def self.create_table db.create_table_sql_list(table_name, *schema.create_info).each {|s| db << s} end # Drops table. def self.drop_table db.execute db.drop_table_sql(table_name) end # Like create_table but invokes drop_table when table_exists? is true. def self.create_table! drop_table if table_exists? create_table end end end
Version data entries
13 entries across 13 versions & 2 rubygems