permission_test.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. const MongoClient = require("mongodb").MongoClient;
  2. const ObjectID = require("mongodb").ObjectID;
  3. const mm = require('./mm.js')
  4. const delay = ms => new Promise(r => setTimeout(r.bind(ms), ms))
  5. ;(async () => {
  6. const mongoClient = new MongoClient("mongodb://localhost:27017/", { useNewUrlParser: true });
  7. const client = await mongoClient.connect()
  8. const db = client.db('mm')
  9. const Savable = mm(db).Savable
  10. //const SlicedSavable = mm(db).sliceSavable([])
  11. //
  12. class User extends Savable{
  13. static get relations(){
  14. return {
  15. children: "parent",
  16. parent: "children",
  17. friends: "friends",
  18. }
  19. }
  20. }
  21. Savable.addClass(User)
  22. //upsert...
  23. let admin = (await Savable.m.User.findOne({login: 'admin'})) ||
  24. (await (new User({login: 'admin'})).save())
  25. console.log(admin)
  26. let looser = (await Savable.m.User.findOne({login: 'looser'})) ||
  27. (await (new User({login: 'looser'})).save())
  28. console.log(looser)
  29. const SlicedSavable = mm(db).sliceSavable([admin._id, ])
  30. class Notebook extends SlicedSavable{
  31. //nothing at all
  32. }
  33. SlicedSavable.addClass(Notebook)
  34. //let notebook = new Notebook({
  35. // brand: 'dell'
  36. // })
  37. // await notebook.save()
  38. // let notebook2 = new Notebook({
  39. // brand: 'hp'
  40. // })
  41. // await notebook2.save()
  42. // console.log(notebook)
  43. // console.log(notebook2)
  44. console.log('findone', await SlicedSavable.m.Notebook.findOne({brand: 'dubovo'}))
  45. for (const notik of SlicedSavable.m.Notebook.find({})){
  46. let n = await notik
  47. //console.log(n)
  48. //await n.delete()
  49. //n.changed = true;
  50. // await n.save()
  51. }
  52. })()