-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjourney-repository.js
74 lines (67 loc) · 2.45 KB
/
journey-repository.js
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
// Inserts entity. Invokes callback(error) when done.
module.exports.insert = function (entity, callback) {
var tableService = getTableService();
createTableIfNotExists(tableService, function(error) {
if (error) {
callback(error);
return;
}
tableService.insertEntity('journey', entity, function (error) {
if (error) {
callback(error);
return;
}
callback(null);
});
});
};
// Deletes entity. Invokes callback(error) when done.
module.exports.delete = function (entity, callback) {
var tableService = getTableService();
tableService.deleteEntity('journey', { PartitionKey: entity.PartitionKey, RowKey: entity.RowKey }, function (error) {
if (error) {
callback(error);
return;
}
callback(null);
});
};
// Returns entities from query. Invokes callback(error, entities) when done.
module.exports.get = function(query, callback) {
var tableService = getTableService();
createTableIfNotExists(tableService, function(error) {
if (error) {
callback(error);
return;
}
// get
tableService.queryEntities(query, function (error, entities) {
if (error) {
callback(error);
return;
}
callback(null, entities);
});
});
}
var createTableIfNotExists = function(tableService, callback) {
tableService.createTableIfNotExists('journey', function(error) {
if (error) {
callback(error);
return;
}
callback(null);
});
};
var getTableService = function () {
var azure = require('azure');
// The NTVS can't see the AppSettings, so if null, must be debugging, use Development Storage
var tableService = process.env.StorageAccountName === undefined
? azure.createTableService("devstoreaccount1",
"Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",
"127.0.0.1:10002")
: azure.createTableService(process.env.StorageAccountName,
process.env.StorageAccountKey,
process.env.StorageAccountTableStoreHost);
return tableService;
};