Skip to content

Commit ea5d984

Browse files
committed
Added users option to createDatabase.
1 parent c484dc1 commit ea5d984

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,22 @@ These functions implement the [HTTP API for manipulating databases](https://docs
349349

350350
#### database.createDatabase
351351

352-
`database.createDatabase(databaseName: string, [callback: Callback]): Promise<Database>`
352+
`database.createDatabase(databaseName: string, [users: Array<Object>], [callback: Callback]): Promise<Database>`
353353

354354
Creates a new database with the given *databaseName*, then passes a new *Database* instance to the callback.
355355

356+
If *users* is specified, it must be an array of objects with the following attributes:
357+
358+
* *username*: the username of the user to create for the database.
359+
* *passwd* (optional): the password of the user. Default: empty.
360+
* *active* (optional): whether the user is active. Default: `true`.
361+
* *extra* (optional): an object containing additional user data.
362+
356363
*Examples*
357364

358365
```js
359366
var db = require('arangojs')();
360-
db.createDatabase('mydb', function (err, database) {
367+
db.createDatabase('mydb', [{username: 'root'}], function (err, database) {
361368
if (err) return console.error(err);
362369
// database is a Database instance
363370
});

lib/database.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,22 @@ extend(Database.prototype, {
204204
this._api['delete']('graph/' + graphName, { dropCollections: dropCollections }, callback);
205205
return promise;
206206
},
207-
createDatabase: function createDatabase(databaseName, cb) {
207+
createDatabase: function createDatabase(databaseName, users, cb) {
208+
if (typeof users === 'function') {
209+
cb = users;
210+
users = undefined;
211+
}
212+
208213
var _promisify11 = promisify(cb);
209214

210215
var promise = _promisify11.promise;
211216
var callback = _promisify11.callback;
212217

213218
var self = this;
214-
self._api.post('database', { name: databaseName }, function (err, res) {
219+
self._api.post('database', {
220+
name: databaseName,
221+
users: users
222+
}, function (err, res) {
215223
if (err) callback(err);else {
216224
callback(null, new Database(extend({}, self._connection.config, { databaseName: databaseName })));
217225
}

src/database.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,17 @@ extend(Database.prototype, {
167167
this._api.delete('graph/' + graphName, {dropCollections: dropCollections}, callback);
168168
return promise;
169169
},
170-
createDatabase: function (databaseName, cb) {
170+
createDatabase: function (databaseName, users, cb) {
171+
if (typeof users === 'function') {
172+
cb = users;
173+
users = undefined;
174+
}
171175
var {promise, callback} = promisify(cb);
172176
var self = this;
173-
self._api.post('database', {name: databaseName}, function (err, res) {
177+
self._api.post('database', {
178+
name: databaseName,
179+
users: users
180+
}, function (err, res) {
174181
if (err) callback(err);
175182
else {
176183
callback(null, new Database(extend(

0 commit comments

Comments
 (0)