-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertOperations.js
More file actions
114 lines (98 loc) · 5.09 KB
/
insertOperations.js
File metadata and controls
114 lines (98 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**************************************************************************
* insertOperations.js
* Author: Taylor Rietz
*
* Simple functions that allow NOAA data insertion into a mysql database.
* Functions exported in module.exports to be used modularly in other project
* files. Insertion currently supported for the following tables:
* -station, dataset, datacategory, locationcategory, datatype, location
* There is an existing dependency between insertion fields and insertion object
* ordering.
* prerequisites: mysql database, './dbInterface.js' module
**************************************************************************/
var dbInterface = require("./dbInterface_safe.js");
/**************************************************************************
* station:
* Accepts a mysql database connection, and a station object from NOAA API
* call. Inserts a single station object into table called 'station'. Single
* row insertion.
**************************************************************************/
module.exports.station = function stationInsert(connectionObj, stationObj){
var query = "insert into station "+
"(noaa_id,mindate,maxdate,name,datacoverage,elevation,latitude,longitude) "+
"values "+
"(?,?,?,?,?,?,?,?)";
dbInterface.runQuery(connectionObj, query, stationObj, dbInterface.emptyCallback);
}
/**************************************************************************
* dataset:
* Accepts a mysql database connection, and a dataset object from NOAA API
* call. Inserts a single dataset object into table called 'dataset'. Single
* row insertion.
**************************************************************************/
module.exports.dataset = function datasetInsert(connectionObj, datasetObj){
var query = "insert into dataset "+
"(noaa_uid,noaa_id,mindate,maxdate,name,datacoverage) "+
"values "+
"(?,?,?,?,?,?)";
dbInterface.runQuery(connectionObj, query, datasetObj, dbInterface.emptyCallback);
}
/**************************************************************************
* datacategory:
* Accepts a mysql database connection, and a datacategory object from NOAA API
* call. Inserts a single datacategory object into table called 'datacategory'.
* Single row insertion.
**************************************************************************/
module.exports.datacategory = function datacategoryInsert(connectionObj, datacategoryObj){
var query = "insert into datacategory "+
"(noaa_id,name) "+
"values "+
"(?,?)";
dbInterface.runQuery(connectionObj, query, datacategoryObj, dbInterface.emptyCallback);
}
/**************************************************************************
* locationcategory:
* Accepts a mysql database connection, and a locationcategory object from NOAA API
* call. Inserts a single locationcategory object into table called 'locationcategory'.
* Single row insertion.
**************************************************************************/
module.exports.locationcategory = function locationcategoryInsert(connectionObj, locationcategoryObj){
var query = "insert into locationcategory "+
"(noaa_id,name) "+
"values "+
"(?,?)";
dbInterface.runQuery(connectionObj, query, locationcategoryObj, dbInterface.emptyCallback);
}
/**************************************************************************
* datatype:
* Accepts a mysql database connection, and a datatype object from NOAA API
* call. Inserts a single datatype object into table called 'datatype'.
* Single row insertion.
**************************************************************************/
module.exports.datatype = function datatypeInsert(connectionObj, datatypeObj){
var query = "insert into datatype "+
"(noaa_id,mindate,maxdate,name,datacoverage) "+
"values "+
"(?,?,?,?,?)";
dbInterface.runQuery(connectionObj, query, datatypeObj, dbInterface.emptyCallback);
}
/**************************************************************************
* location:
* Accepts a mysql database connection, and a location object from NOAA API
* call. Inserts a single location object into table called 'location'.
* Single row insertion.
**************************************************************************/
module.exports.location = function locationInsert(connectionObj, locationObj){
var query = "insert into location "+
"(noaa_id,mindate,maxdate,name,datacoverage) "+
"values "+
"(?,?,?,?,?)";
dbInterface.runQuery(connectionObj, query, locationObj, dbInterface.emptyCallback);
}
module.exports.gsom = function gsomInsert(connectionObj, gsomObj){
var query = "insert into gsom "+
"(datatype_id,station_id,date,attributes,value) "+
"values "+
"( (select id from datatype where noaa_id = ?),(select id from station where noaa_id = ?),?,?,?)";
dbInterface.runQuery(connectionObj, query, gsomObj, dbInterface.emptyCallback);
}