mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
documentdb improvements
This commit is contained in:
@@ -13,6 +13,22 @@ docDBClient.createDatabase({ id: 'foo' }, undefined, (error, result) => {
|
||||
}
|
||||
});
|
||||
|
||||
var dbQuerySpec: docDB.SqlQuerySpec = {query: 'SELECT * FROM database d WHERE d.id = @id', parameters: [{name: 'id', value: 'foo'}]}
|
||||
docDBClient.queryDatabases(dbQuerySpec).toArray((error, result) => {
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.body);
|
||||
}
|
||||
else {
|
||||
if (result.length < 1) {
|
||||
throw new Error('Database foo not found');
|
||||
}
|
||||
else {
|
||||
console.log('Found database: ' + result[0].id);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
docDBClient.createCollection('database', { id: 'foo' }, undefined, (error, result) => {
|
||||
|
||||
if (error) {
|
||||
@@ -40,6 +56,41 @@ docDBClient.createStoredProcedure('collection', procedure, undefined, (error, re
|
||||
}
|
||||
});
|
||||
|
||||
var trigger: docDB.Trigger = {
|
||||
id: 'trigger-one',
|
||||
body: function () {
|
||||
console.log('bar');
|
||||
},
|
||||
triggerType: 'pre',
|
||||
triggerOperation: 'all'
|
||||
}
|
||||
|
||||
docDBClient.createTrigger('collection', trigger, undefined, (error, result) => {
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.body);
|
||||
}
|
||||
else {
|
||||
console.log('Created trigger: ' + result.id);
|
||||
}
|
||||
});
|
||||
|
||||
var triggerQuerySpec: docDB.SqlQuerySpec = {query: 'SELECT * FROM trigger t WHERE t.id = @id', parameters: [{name: 'id', value: 'trigger-foo'}]}
|
||||
docDBClient.queryTriggers('collection', triggerQuerySpec).toArray((error, result) => {
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.body);
|
||||
}
|
||||
else {
|
||||
if (result.length < 1) {
|
||||
throw new Error('Trigger trigger-foo not found');
|
||||
}
|
||||
else {
|
||||
console.log('Found trigger: ' + result[0].id);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var document: docDB.NewDocument<{ val: string }> = {
|
||||
id: '10'
|
||||
};
|
||||
@@ -51,6 +102,16 @@ docDBClient.createDocument('collection', document, undefined, (error, result) =>
|
||||
}
|
||||
else {
|
||||
console.log('Created document: ' + result.id);
|
||||
|
||||
docDBClient.replaceDocument(result._self, document, undefined, (subError, subResult) => {
|
||||
|
||||
if (subError) {
|
||||
throw new Error(subError.body);
|
||||
}
|
||||
else {
|
||||
console.log('Replaced document: ' + subResult.id);
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user