script.io.js 2026.127.27 → 2026.127.1056

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -587,6 +587,9 @@ Define (Function.mongo, "db", class {
587
587
  db (db) {
588
588
  return new Function.mongo.db.client (this.client, db);
589
589
  }
590
+ use (db) {
591
+ return this.db (db);
592
+ }
590
593
  });
591
594
 
592
595
  Define (Function.mongo.db, "client", class {
@@ -604,11 +607,52 @@ Define (Function.mongo.db, "collection", class {
604
607
  this.client = client;
605
608
  this.db = db;
606
609
  this.collection = this.db.collection (collection);
610
+ this.option = {filter: {}}
611
+ }
612
+ find (filter) {
613
+ if (typeof filter === "string") this.option.filter = {serial: filter}
614
+ else this.option.filter = filter || {}
615
+ return this;
616
+ }
617
+ limit () {
618
+ if (arguments.length === 1) this.option.limit = arguments [0];
619
+ if (arguments.length === 2) {
620
+ this.option.offset = arguments [0];
621
+ this.option.limit = arguments [1];
622
+ }
623
+ return this;
624
+ }
625
+ select (filter, option) {
626
+ var __ = function (mongo) {
627
+ return new Promise (async function (resolve, reject) {
628
+ var error, data;
629
+ try {
630
+ if (mongo.option.limit === 1) data = await mongo.collection.findOne (mongo.option.filter);
631
+ else data = await mongo.collection.find (mongo.option.filter).toArray ();
632
+ }
633
+ catch (e) { error = true; }
634
+ resolve ({error, data});
635
+ });
636
+ }
637
+ return __ (this);
638
+ }
639
+ insert (data) {
640
+ var __ = function (mongo) {
641
+ return new Promise (async function (resolve, reject) {
642
+ var error, result;
643
+ try {
644
+ if (Array.isArray (data)) result = await mongo.collection.insertMany (data, {ordered: false, forceServerObjectId: true});
645
+ }
646
+ catch (e) { error = true; }
647
+ resolve ({error, result});
648
+ });
649
+ }
650
+ return __ (this);
607
651
  }
608
- select () {
652
+ truncate () {
609
653
  var __ = function (mongo) {
610
654
  return new Promise (async function (resolve, reject) {
611
- var result = mongo.collection.find ({}).toArray ();
655
+ var result = await mongo.collection.deleteMany ({});
612
656
  resolve (result);
613
657
  });
614
658
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "script.io.js",
3
3
  "description": "Hello World",
4
- "version": "2026.127.027",
4
+ "version": "2026.127.1056",
5
5
  "author": "Seindi Rahmat Barus <xseindi@gmail.com>",
6
6
  "contributors": [
7
7
  "Seindi Rahmat Barus <xseindi@gmail.com>"