Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ozym committed Nov 23, 2024
1 parent cccbfab commit 62354f0
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions meta/sqlite/station.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var datum = Table{
return "SELECT datum_id FROM datum WHERE datum = ?"
},
Insert: func() string {
return "INSERT OR IGNORE INTO datum (datum) VALUES (?);"
return "INSERT INTO datum (datum) VALUES (?) ON CONFLICT(datum) DO NOTHING;"
},
Fields: []string{"Datum"},
}
Expand All @@ -37,7 +37,7 @@ var method = Table{
return "SELECT method_id FROM method WHERE method = ?"
},
Insert: func() string {
return "INSERT OR IGNORE INTO method (method) VALUES (?);"
return "INSERT INTO method (method) VALUES (?) ON CONFLICT(method) DO NOTHING;"
},
Fields: []string{"Method"},
}
Expand All @@ -59,7 +59,7 @@ var network = Table{
return "SELECT network_id FROM network WHERE network = ?"
},
Insert: func() string {
return "INSERT OR IGNORE INTO network (network, external, description, restricted) VALUES (?, ?, ?, ?);"
return "INSERT INTO network (network, external, description, restricted) VALUES (?, ?, ?, ?);"
},
Fields: []string{"Network", "External", "Description", "Restricted"},
}
Expand Down Expand Up @@ -87,7 +87,7 @@ var station = Table{
return "SELECT station_id FROM station WHERE station = ?"
},
Insert: func() string {
return fmt.Sprintf("INSERT OR IGNORE INTO station (datum_id, station, name, latitude, longitude, elevation, depth, start_date, end_date) VALUES ((%s), ?, ?, ?, ?, ?, ?, ?, ?);", datum.Select())
return fmt.Sprintf("INSERT INTO station (datum_id, station, name, latitude, longitude, elevation, depth, start_date, end_date) VALUES ((%s), ?, ?, ?, ?, ?, ?, ?, ?);", datum.Select())
},
Fields: []string{"Datum", "Station", "Name", "Latitude", "Longitude", "Elevation", "Depth", "Start Date", "End Date"},
}
Expand All @@ -110,6 +110,7 @@ var stationNetwork = Table{
station.Select(), network.Select())
},
Insert: func() string {
// not all networks are in the networks table so simply ignore any that fail
return fmt.Sprintf("INSERT OR IGNORE INTO station_network (station_id, network_id) VALUES ((%s), (%s));",
station.Select(), network.Select())
},
Expand Down Expand Up @@ -152,7 +153,7 @@ var site = Table{
return fmt.Sprintf("SELECT site_id FROM site WHERE station_id = (%s) AND location = ?", station.Select())
},
Insert: func() string {
return fmt.Sprintf("INSERT OR IGNORE INTO site (station_id, datum_id, location, latitude, longitude, elevation, depth, survey, start_date, end_date) VALUES ((%s), (%s), ?, ?, ?, ?, ?, ?, ?, ?);",
return fmt.Sprintf("INSERT INTO site (station_id, datum_id, location, latitude, longitude, elevation, depth, survey, start_date, end_date) VALUES ((%s), (%s), ?, ?, ?, ?, ?, ?, ?, ?);",
station.Select(), datum.Select())
},

Expand Down Expand Up @@ -193,7 +194,7 @@ var sample = Table{
return "SELECT sample_id FROM sample WHERE station = ?"
},
Insert: func() string {
return fmt.Sprintf("INSERT OR IGNORE INTO sample (datum_id, station, name, latitude, longitude, elevation, depth, start_date, end_date) VALUES ((%s), ?, ?, ?, ?, ?, ?, ?, ?);",
return fmt.Sprintf("INSERT INTO sample (datum_id, station, name, latitude, longitude, elevation, depth, start_date, end_date) VALUES ((%s), ?, ?, ?, ?, ?, ?, ?, ?);",
datum.Select())
},
Fields: []string{"Datum", "Station", "Name", "Latitude", "Longitude", "Elevation", "Depth", "Start Date", "End Date"},
Expand Down Expand Up @@ -232,7 +233,7 @@ END;
var point = Table{
Create: pointCreate,
Insert: func() string {
return fmt.Sprintf("INSERT OR IGNORE INTO point (sample_id, datum_id, location, latitude, longitude, elevation, depth, survey, start_date, end_date) VALUES ((%s), (%s), ?, ?, ?, ?, ?, ?, ?, ?);",
return fmt.Sprintf("INSERT INTO point (sample_id, datum_id, location, latitude, longitude, elevation, depth, survey, start_date, end_date) VALUES ((%s), (%s), ?, ?, ?, ?, ?, ?, ?, ?);",
sample.Select(), datum.Select())
},
Fields: []string{"Point", "Datum", "Location", "Latitude", "Longitude", "Elevation", "Depth", "Survey", "Start Date", "End Date"},
Expand Down Expand Up @@ -271,6 +272,7 @@ END;
var feature = Table{
Create: featureCreate,
Insert: func() string {
// currently a feature could reference a site or a point or a sample, solution is consolidation.
return fmt.Sprintf("INSERT OR IGNORE INTO feature (site_id, sublocation, property, description, aspect, start_date, end_date) VALUES ((%s), ?, ?, ?, ?, ?, ?);",
site.Select())
},
Expand Down Expand Up @@ -303,6 +305,7 @@ var class = Table{
return fmt.Sprintf("SELECT class_id FROM class WHERE station_id = (%s)", station.Select())
},
Insert: func() string {
// not all stations are in the stations file, ignore any conflicts for now
return fmt.Sprintf("INSERT OR IGNORE INTO class (station_id, site_class, vs30, vs30_quality, tsite, tsite_method, tsite_quality, basement_depth, depth_quality, link, notes) VALUES ((%s), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", station.Select())
},
Fields: []string{"Station", "Site Class", "Vs30", "Vs30 Quality", "Tsite", "Tsite Method", "Tsite Quality", "Basement Depth", "Depth Quality", "Link", "Notes"},
Expand Down

0 comments on commit 62354f0

Please sign in to comment.