-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
72 lines (62 loc) · 1.77 KB
/
main.js
File metadata and controls
72 lines (62 loc) · 1.77 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
var shortid = require('shortid');
var low = require('lowdb')
var FileAsync = require('lowdb/adapters/FileAsync')
var adapter = new FileAsync('db.json')
low(adapter).then(
function (db) {
// Set some defaults (required if your JSON file is empty)
db.defaults({
topic: [],
author: []
}).write();
// db.get('author').push({
// id:1,
// name:'egoing',
// profile:'developer'
// }).write();
// db.get('topic').push({
// id:1,
// title:'lowdb',
// description:'lowdb is ...',
// author:1
// }).write();
// db.get('topic').push({
// id: 2,
// title: 'mysql',
// description: 'mysql is ...',
// author: 1
// }).write();
// console.log(
// db.get('topic')
// .find({title:'lowdb', author:1})
// .value()
// );
// db.get('topic')
// .find({id:2})
// .assign({title:'MySQL & MariaDB'})
// .write();
// db.get('topic')
// .remove({
// id: 2
// })
// .write();
var sid = shortid.generate();
db.get('author')
.push({
id: sid,
name: 'duru',
profile: 'db admin'
}).write().then(function(){
console.log('add author');
});
db.get('topic')
.push({
id: shortid.generate(),
title: 'MSSQL',
description: 'MSSQL is ...',
author: sid
}).write().then(function(){
console.log('add topic');
});
}
)