NeDB, na razie bez ostatniego ćwiczenia
This commit is contained in:
1 parent
a1f73fe0c1
commit
8fc98ebf9d
1516 files changed
+255410
No files matched your search
@@ -0,0 +1,92 @@
|
||||
const Datastore = require('@seald-io/nedb');
|
||||
|
||||
// const col1 = new Datastore({
|
||||
// filename: 'kolekcja.db',
|
||||
// autoload: true
|
||||
// });
|
||||
|
||||
// przykłady z punktu 3
|
||||
|
||||
// 1
|
||||
// const doc = {
|
||||
// a: "a",
|
||||
// b: "b"
|
||||
// };
|
||||
|
||||
// col1.insert(doc, function(err, newDoc) {
|
||||
// console.log("Dodano dokument (obiekt): ",
|
||||
// newDoc, ", unikalne id dokumentu: ",
|
||||
// newDoc._id
|
||||
// );
|
||||
// });
|
||||
|
||||
// 2
|
||||
// console.log("Przed for: " + new Date().getMilliseconds());
|
||||
|
||||
// for(let i = 0; i < 3; i++) {
|
||||
// let doc = {
|
||||
// a: "a"+i,
|
||||
// b: "b"+i
|
||||
// };
|
||||
|
||||
// col1.insert(doc, function(err, newDoc) {
|
||||
// console.log("id: ", newDoc._id,
|
||||
// "Dodano: " + new Date().getMilliseconds()
|
||||
// );
|
||||
// });
|
||||
// }
|
||||
|
||||
// console.log("Po for: " + new Date().getMilliseconds());
|
||||
|
||||
// 3
|
||||
// col1.findOne({ _id: 'AsiOCenewqMwoXok' }, function(err, doc) {
|
||||
// console.log("Obiekt pobrany z bazy: ", doc);
|
||||
// });
|
||||
|
||||
// 4
|
||||
// col1.find({}, function(err, docs) {
|
||||
// console.log("Tablica obiektów pobrana z bazy: " + docs);
|
||||
|
||||
// docs.forEach(doc => {
|
||||
// console.log(doc);
|
||||
// });
|
||||
// });
|
||||
|
||||
// 5
|
||||
// col1.find({ a: "a1" }, function(err, docs) {
|
||||
// console.log(docs);
|
||||
// });
|
||||
|
||||
// 6
|
||||
// col1.count({}, function(err, count) {
|
||||
// console.log(count);
|
||||
// })
|
||||
|
||||
// 7
|
||||
// col1.count({a: "a1"}, function(err, count) {
|
||||
// console.log(count);
|
||||
// })
|
||||
|
||||
// 8
|
||||
// col1.remove({ a: "a2"}, {}, function(err, numRemoved) {
|
||||
// console.log("usunięto " + numRemoved + " dokumentów")
|
||||
// });
|
||||
|
||||
// 9
|
||||
// col1.remove({ a: "a" }, { multi: true }, function(err, numRemoved) {
|
||||
// console.log(`Usunięto ${numRemoved} dokumentów.`);
|
||||
// });
|
||||
|
||||
// 10
|
||||
// col1.remove({}, { multi: true }, function(err, numRemoved) {
|
||||
// console.log(`Usunięto ${numRemoved} dokumentów.`);
|
||||
// });
|
||||
|
||||
const col2 = new Datastore({
|
||||
filename: 'users.db',
|
||||
autoload: true
|
||||
});
|
||||
|
||||
col2.insert({login: "admin", password: "admin", timestamp: new Date().getTime()}, function(err, doc) {
|
||||
console.log("dodano użytkownika", doc.login);
|
||||
});
|
||||
Reference in new issue
Block a user