var Datastore = require('nedb-promise');
var mysql = require('mysql');
var config = require('../config/database.json');
var mysqlPool = mysql.createPool(config.XMLY5000);
var storePath = `${__dirname}/store/`;
console.log(storePath);
module.exports = {
    "XMLY5000": {
        "query": function(sql, params) {
            return new Promise(function(resolve, reject) {
                mysqlPool.getConnection(function(err, conn) {
                    if (err) {
                        console.error(err);
                        reject(err);
                        return;
                    }
                    conn.query(sql, params || [], function(e, results, field) {
                        if (e) {
                            console.error(e);
                            reject(e);
                        } else
                            resolve(results);
                    });
                    conn.release();
                });

            });
        }
    },
    p:{

    },
    "items": Datastore({
        filename: `${storePath}items.db`,
        autoload: true
    }),
    "pcust": Datastore({
        filename: `${storePath}pcust.db`,
        autoload: true
    }),
    "sstock": Datastore({
        filename: `${storePath}sstock.db`,
        autoload: true
    }),
    "sorddt": Datastore({
        filename: `${storePath}sorddt.db`,
        autoload: true
    })
}

@@ -212,31 +212,789 @@
 %60;%0D%0A
-console.log(storePath);
+%0D%0Alet items = Datastore(%7B%0D%0A    filename: %60$%7BstorePath%7Ditems.db%60,%0D%0A    autoload: true%0D%0A%7D);%0D%0A%0D%0Aitems.ensureIndex(%7B%0D%0A    fieldName%EF%BC%9A ' CustomerNO'%0D%0A%7D%EF%BC%8Cfunction%EF%BC%88 err%EF%BC%89 %7B%0D%0A    console.error(err);%0D%0A%7D);%0D%0Aitems.ensureIndex(%7B%0D%0A    fieldName%EF%BC%9A ' SK_BCODE'%0D%0A%7D%EF%BC%8Cfunction%EF%BC%88 err%EF%BC%89 %7B%0D%0A    console.error(err);%0D%0A%7D);%0D%0A%0D%0A%0D%0A%0D%0Alet pcust = Datastore(%7B%0D%0A    filename: %60$%7BstorePath%7Dpcust.db%60,%0D%0A    autoload: true%0D%0A%7D);%0D%0A%0D%0Alet sstock = Datastore(%7B%0D%0A    filename: %60$%7BstorePath%7Dsstock.db%60,%0D%0A    autoload: true%0D%0A%7D);%0D%0A%0D%0Asstock.ensureIndex(%7B%0D%0A    fieldName%EF%BC%9A 'SK_BCODE'%0D%0A%7D%EF%BC%8Cfunction%EF%BC%88 err%EF%BC%89 %7B%0D%0A    console.error(err);%0D%0A%7D);%0D%0A%0D%0A%0D%0Alet sorddt = Datastore(%7B%0D%0A    filename: %60$%7BstorePath%7Dsorddt.db%60,%0D%0A    autoload: true%0D%0A%7D);%0D%0A%0D%0Asorddt.ensureIndex(%7B%0D%0A    fieldName%EF%BC%9A 'OD_CTNO'%0D%0A%7D%EF%BC%8Cfunction%EF%BC%88 err%EF%BC%89 %7B%0D%0A    console.error(err);%0D%0A%7D);%0D%0A%0D%0A%0D%0A
 %0D%0Amo
@@ -1774,16 +1774,17 @@
 %0D%0A    p:
+ 
 %7B%0D%0A%0D%0A   
@@ -1805,405 +1805,79 @@
 s%22: 
-Datastore(%7B%0D%0A        filename: %60$%7BstorePath%7Ditems.db%60,%0D%0A        autoload: true%0D%0A    %7D),%0D%0A    %22pcust%22: Datastore(%7B%0D%0A        filename: %60$%7BstorePath%7Dpcust.db%60,%0D%0A        autoload: true%0D%0A    %7D),%0D%0A    %22sstock%22: Datastore(%7B%0D%0A        filename: %60$%7BstorePath%7Dsstock.db%60,%0D%0A        autoload: true%0D%0A    %7D),%0D%0A    %22sorddt%22: Datastore(%7B%0D%0A        filename: %60$%7BstorePath%7Dsorddt.db%60,%0D%0A        autoload: true%0D%0A    %7D)%0D%0A%7D%0D%0A
+items,%0D%0A    %22pcust%22: pcust,%0D%0A    %22sstock%22: sstock,%0D%0A    %22sorddt%22: sorddt%0D%0A%7D

add nedb index