Method: FreeZipcodeData::ZipcodeTable#build

Defined in:
lib/free_zipcode_data/zipcode_table.rb

#buildObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/free_zipcode_data/zipcode_table.rb', line 7

def build
  schema = "    create table \#{tablename} (\n      id integer not null primary key,\n      code varchar(10) not null,\n      state_id integer,\n      city varchar(255),\n      area_code varchar(3),\n      lat float,\n      lon float,\n      accuracy varchar(8)\n    )\n  SQL\n  database.execute_batch(schema)\n\n  ndx = <<-SQL\n    CREATE UNIQUE INDEX \"main\".\"unique_zipcode\"\n    ON \#{tablename} (state_id, code, city COLLATE NOCASE ASC);\n  SQL\n  database.execute_batch(ndx)\nend\n"