Sha256: 3708558701f46dd4d5ff9f73d7fa85b23efa4e357e33d0b9b0395c8d17ff6d4b

Contents?: true

Size: 1.35 KB

Versions: 10

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

# database handling for eDen Db
class Database
  class << self
    Sequel.extension :migration

    def db_access
      Sequel.connect("sqlite://eden.sqlite3")
    end

    def create_table(table_name)
      eden = Sequel.connect("sqlite://eden.sqlite3")
      unless eden.table_exists?(table_name)
        eden.create_table table_name.to_sym do
          primary_key "#{table_name}_id".to_sym
        end
      end
    end

    # def create_column(table, column_name, type)
    #   eden = Sequel.connect("sqlite://eden.sqlite3")
    #   if eden.table_exists?(table)
    #     unless eden.schema(table).any? { |column| column.first == column_name }
    #       Sequel.migration do
    #         change do
    #           add_column table, column_name, type
    #         end
    #       end.apply(eden, :up)
    #     end
    #   end
    # end
    def create_column(table, column_name, type)
      eden = Sequel.connect("sqlite://eden.sqlite3")
      if eden.table_exists?(table)
        begin
          Sequel.migration do
            change do
              add_column table, column_name, type unless eden.schema(table).any? { |column| column.first == column_name }
            end
          end.apply(eden, :up)
        rescue Sequel::DatabaseError => e
          puts "error adding column  : #{e.message}"
        end
      end
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
atome-0.5.6.5.4 vendor/assets/server/database.rb
atome-0.5.6.5.1 vendor/assets/server/database.rb
atome-0.5.6.4.8 vendor/assets/server/database.rb
atome-0.5.6.4.5 vendor/assets/server/database.rb
atome-0.5.6.4.2 vendor/assets/server/database.rb
atome-0.5.6.4.1 vendor/assets/server/database.rb
atome-0.5.6.4.0 vendor/assets/server/database.rb
atome-0.5.6.3.9 vendor/assets/server/database.rb
atome-0.5.6.3.6 vendor/assets/server/database.rb
atome-0.5.6.3.5 vendor/assets/server/database.rb