Class: FBTiles::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/fbtiles/database.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ Database

Returns a new instance of Database.



9
10
11
12
13
14
15
16
# File 'lib/fbtiles/database.rb', line 9

def initialize(path = nil)
  storage_type = path ? "//#{path}" : ':memory:'

  @path = path
  @db = Sequel.connect("#{self.class.driver}:#{storage_type}")

  create_schema!
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/fbtiles/database.rb', line 7

def path
  @path
end

Class Method Details

.driverObject

def initialize



18
19
20
# File 'lib/fbtiles/database.rb', line 18

def self.driver
  @driver ||= RUBY_PLATFORM == 'java' ? 'jdbc:sqlite' : 'sqlite'
end

Instance Method Details

#adapterObject

def self.driver



22
23
24
# File 'lib/fbtiles/database.rb', line 22

def adapter
  @db
end

#create_schema!Object

def insert_tiles



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fbtiles/database.rb', line 38

def create_schema!
  @db.create_table :bounds do
    Integer :zoom
    Integer :collared
    Integer :maxX
    Integer :maxY
    Integer :minX
    Integer :minY

    primary_key [:zoom, :collared]
  end

  @db.create_table :datatypes do
    Integer :id, :primary_key => true
    Text :datatype # PNG or JPG only!

    index :datatype, unique: true, name: 'datatypes_idx'
  end

  @db.create_table :tiles do
    Integer :tilekey, :primary_key => true
    Integer :zoom_level
    Integer :tile_row
    Integer :tile_column
    Blob    :tile_data
    Integer :tile_datatypes_id
    Blob    :tile_collar_data
    Integer :tile_collar_datatypes_id

    index [:zoom_level, :tile_row, :tile_column], name: 'tiles_idx'        
  end
end

#insert_bounds(records) ⇒ Object

def adapter



26
27
28
# File 'lib/fbtiles/database.rb', line 26

def insert_bounds(records)
  @db[:bounds].multi_insert(records)
end

#insert_datatypes(records) ⇒ Object

def insert_bounds



30
31
32
# File 'lib/fbtiles/database.rb', line 30

def insert_datatypes(records)
  @db[:datatypes].multi_insert(records)
end

#insert_tiles(records) ⇒ Object

def insert_datatypes



34
35
36
# File 'lib/fbtiles/database.rb', line 34

def insert_tiles(records)
  @db[:tiles].multi_insert(records)
end