Class: Hanami::CLI::Commands::App::DB::Utils::Sqlite Private

Inherits:
Database
  • Object
show all
Defined in:
lib/hanami/cli/commands/app/db/utils/sqlite.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 2.2.0

Defined Under Namespace

Classes: Failure

Constant Summary

Constants inherited from Database

Database::DATABASE_CLASS_RESOLVER

Instance Attribute Summary

Attributes inherited from Database

#gateway_name, #slice, #system_call

Instance Method Summary collapse

Methods inherited from Database

#applied_migrations, #connection, database_class, #database_uri, #database_url, #db_config_dir?, #db_config_path, from_slice, #gateway, #initialize, #migrations_dir?, #migrations_path, #migrator, #run_migrations, #schema_migrations_sql_dump, #sequel_migrator, #structure_file

Constructor Details

This class inherits a constructor from Hanami::CLI::Commands::App::DB::Utils::Database

Instance Method Details

#exec_create_commandObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.2.0



28
29
30
31
32
33
34
# File 'lib/hanami/cli/commands/app/db/utils/sqlite.rb', line 28

def exec_create_command
  return true if exists?

  FileUtils.mkdir_p(File.dirname(file_path))

  system_call.call(%(sqlite3 #{file_path} "VACUUM;"))
end

#exec_drop_commandObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.2.0



38
39
40
41
42
43
44
45
46
47
# File 'lib/hanami/cli/commands/app/db/utils/sqlite.rb', line 38

def exec_drop_command
  begin
    File.unlink(file_path) if exists?
  rescue => e
    # Mimic a system_call result
    return Failure.new(e.message)
  end

  true
end

#exec_dump_commandObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.2.0



57
58
59
# File 'lib/hanami/cli/commands/app/db/utils/sqlite.rb', line 57

def exec_dump_command
  system_call.call(%(sqlite3 #{file_path} ".schema --indent --nosys" > #{structure_file}))
end

#exec_load_commandObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.2.0



63
64
65
# File 'lib/hanami/cli/commands/app/db/utils/sqlite.rb', line 63

def exec_load_command
  system_call.call("sqlite3 #{file_path} < #{structure_file}")
end

#exists?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 2.2.0



51
52
53
# File 'lib/hanami/cli/commands/app/db/utils/sqlite.rb', line 51

def exists?
  File.exist?(file_path)
end

#nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.2.0



69
70
71
72
73
74
# File 'lib/hanami/cli/commands/app/db/utils/sqlite.rb', line 69

def name
  # Sequel expects sqlite:// URIs to operate the same as file:// URIs: 2 slashes for
  # a relative path, 3 for an absolute path. In the case of 2 slashes, the first part
  # of the path is considered by Ruby's `URI` as the `#host`.
  @name ||= "#{database_uri.host}#{database_uri.path}"
end