Class: Packagecloud::Maven::Importer::Database
- Inherits:
-
Object
- Object
- Packagecloud::Maven::Importer::Database
- Defined in:
- lib/packagecloud/maven/importer/database.rb
Constant Summary collapse
- CREATE_SCHEMA =
<<-SQL CREATE TABLE IF NOT EXISTS artifacts (full_path TEXT PRIMARY KEY, base_path TEXT, state TEXT); SQL
Instance Attribute Summary collapse
-
#database ⇒ Object
Returns the value of attribute database.
Instance Method Summary collapse
- #clear! ⇒ Object
- #finish!(full_path) ⇒ Object
-
#initialize(path:) ⇒ Database
constructor
A new instance of Database.
- #peek ⇒ Object
- #push(full_path, base_path) ⇒ Object
- #queued_count ⇒ Object
- #reset! ⇒ Object
- #total_count ⇒ Object
Constructor Details
#initialize(path:) ⇒ Database
Returns a new instance of Database.
13 14 15 16 |
# File 'lib/packagecloud/maven/importer/database.rb', line 13 def initialize(path:) self.database = SQLite3::Database.new(path) self.database.execute(CREATE_SCHEMA) end |
Instance Attribute Details
#database ⇒ Object
Returns the value of attribute database.
7 8 9 |
# File 'lib/packagecloud/maven/importer/database.rb', line 7 def database @database end |
Instance Method Details
#clear! ⇒ Object
18 19 20 21 22 |
# File 'lib/packagecloud/maven/importer/database.rb', line 18 def clear! self.database.execute <<-SQL DELETE FROM artifacts; SQL end |
#finish!(full_path) ⇒ Object
30 31 32 33 34 |
# File 'lib/packagecloud/maven/importer/database.rb', line 30 def finish!(full_path) self.database.execute <<-SQL UPDATE artifacts SET state='uploaded' WHERE (full_path='#{full_path}'); SQL end |
#peek ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/packagecloud/maven/importer/database.rb', line 49 def peek full_path, base_path = self.database.get_first_row("SELECT * from artifacts where state='queued';") if full_path [full_path, base_path] else nil end end |
#push(full_path, base_path) ⇒ Object
24 25 26 27 28 |
# File 'lib/packagecloud/maven/importer/database.rb', line 24 def push(full_path, base_path) self.database.execute <<-SQL INSERT OR IGNORE INTO artifacts VALUES('#{full_path}', '#{base_path}', 'queued'); SQL end |
#queued_count ⇒ Object
41 42 43 |
# File 'lib/packagecloud/maven/importer/database.rb', line 41 def queued_count self.database.get_first_value "SELECT COUNT(*) FROM artifacts where state='queued';" end |
#reset! ⇒ Object
36 37 38 39 |
# File 'lib/packagecloud/maven/importer/database.rb', line 36 def reset! self.database.execute("DROP TABLE artifacts;") self.database.execute(CREATE_SCHEMA) end |
#total_count ⇒ Object
45 46 47 |
# File 'lib/packagecloud/maven/importer/database.rb', line 45 def total_count self.database.get_first_value "SELECT COUNT(*) FROM artifacts;" end |