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CAAE,MAAO,GACL,KAAK,OAAO,MAAM,UAAU,EAAM,WAClC,KAAK,OAAO,MAAM,EACtB,CACJ,CAMA,gBAAM,SACI,KAAK,OAAM,EACrB,CAMA,SAAM,CAAI,SACA,KAAK,KAAK,IAAI,GACpB,IACI,IAAI,QAAa,EAAE,GAAG,GAAI,OAAO,IAAI,KAAK,MAC1C,KAAK,OAAO,KAAK,2BAA2B,KAC5C,KAAK,OAAO,MAAM,GAClB,KAAK,GAAK,CACd,CAAE,MAAO,GACL,KAAK,OAAO,MAAM,UAAU,EAAM,WAClC,KAAK,OAAO,MAAM,EACtB,CACJ,CAKA,eAAM,GACF,IAAI,KAAK,GAEL,OADA,KAAK,OAAO,MAAM,4DACX,EAGX,aADkB,EAAE,GAAG,KAAK,IAAI,YAAY,IAAI,KAAK,KAEzD,CAMA,YAAM,CAAO,GACT,IACI,IAAI,QAAe,EAAK,IAAI,KAAK,MACjC,aAAa,EAAO,SACxB,CAAE,MAAO,GACL,KAAK,OAAO,MAAM,UAAU,EAAM,WAClC,KAAK,OAAO,MAAM,EACtB,CACJ,CAOA,UAAM,CAAK,EAAO,EAAQ,GACtB,IAAI,KAAK,GAEL,OADA,KAAK,OAAO,MAAM,sDACX,EAEX,IAAI,EAAQ,EAAQ,EAAI,EAAE,GAAG,KAAK,IAAI,MAAM,GAAO,MAAM,GACnD,EAAE,GAAG,KAAK,IAAI,MAAM,GAE1B,aADmB,EAAK,IAAI,KAAK,OACnB,SAClB,EAGJ,OAAO,QAAQ,SAAW","file":"/npm/rethinkdb-wrapper@1.0.1/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/rethinkdb-wrapper@1.0.1/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const r = require('rethinkdb');\n\n/**\n * @class\n * @author Snake\n * @description rethinkdb database class\n */\n\nclass Database {\n    /**\n     * create instanse\n     * @param {obejct} dbconfig\n     * @param {string} dbconfig.host database host\n     * @param {number} dbconfig.port\n     * @param {string} dbconfig.user\n     * @param {string} dbconfig.password\n     * @param {string} dbconfig.db\n     */\n     constructor(dbconfig, logger){\n        let {\n            host:host = 'localhost',\n            port:port = 28015,\n            user:user = 'admin',\n            password:password = 'password',\n            db:db = null\n        } = dbconfig || {};\n\n        this.innerLogger = {\n            info: console.info,\n            warn: console.warn,\n            error: console.error,\n            debug: console.debug\n        };\n\n        this.host = host;\n        this.port = port;\n        this.user = user;\n        this.password = password;\n        this.db = db;\n        this.conn = {open: false};\n        this.logger = (typeof(logger) == 'object' && typeof(logger.info) == 'function')\n            ? logger : this.innerLogger;\n    }\n\n     /**\n      * Connect to database\n      */\n     async open(){\n        this.logger.info('Try connect to database');\n        try {\n            this.conn = await r.connect({\n                host: this.host,\n                port: this.port,\n                user: this.user,\n                password: this.password,\n                db: this.db\n            });\n            this.logger.info(`Connected`);\n\n            this.conn.on('error', (error)=>{\n                this.logger.error(`database error: ${error.message}`);\n                this.logger.debug(error);\n            });\n\n            this.conn.on('connect', ()=>{\n                this.logger.info(`connected to database`);\n            });\n\n            this.conn.on('timeout', ()=>{\n                this.logger.error(`database socker error`);\n            });\n\n            this.conn.on('close', ()=>{\n                this.logger.info('database connection close');\n            });\n\n        } catch (error) {\n            this.logger.error(`Error: ${error.message}`);\n            this.logger.debug(error);\n        }\n    }\n\n    /**\n     * disconnect from database\n     */\n    async close(wait = true){\n        this.logger.info(`Try disconnect from database`);\n        try {\n            await this.conn.close([{noreplyWait: wait}]);\n        } catch (error) {\n            this.logger.error(`Error: ${error.message}`);\n            this.logger.debug(error);\n        }\n    }\n\n    /**\n     * force connection close\n     */\n\n    async forceClose(){\n        await this.close(false);\n    }\n\n    /**\n     * change default database\n     * @param {string} db database name\n     */\n    async use(db){\n        await this.conn.use(db);\n        try {\n            let info = await r.db(db).info().run(this.conn);\n            this.logger.info(`database was changed to ${db}`);\n            this.logger.debug(info);\n            this.db = db;\n        } catch (error) {\n            this.logger.error(`Error: ${error.message}`);\n            this.logger.debug(error);\n        }\n    }\n\n    /** \n     * return table list\n    */\n    async tableList(){\n        if(!this.db){\n            this.logger.error('Error: getting table list error - database not selected');\n            return false;\n        }\n        let TList = await r.db(this.db).tableList().run(this.conn);\n        return TList;\n    }\n\n    /**\n     * \n     * @param {object} reql REQL string\n     */\n    async select(reql){\n        try {\n            let cursor = await reql.run(this.conn);\n            return await cursor.toArray();\n        } catch (error) {\n            this.logger.error(`Error: ${error.message}`);\n            this.logger.error(error);\n        }        \n    }\n\n    /**\n     * read data from table\n     * @param {string} table rethinkdb table\n     * @param {number} limit limit result data\n     */\n    async read(table, limit = 0){\n        if(!this.db){\n            this.logger.error('Error: reading from table - database not selected');\n            return false;\n        }\n        let reql = (limit > 0)? r.db(this.db).table(table).limit(limit) \n            : r.db(this.db).table(table);\n        let cursor = await reql.run(this.conn);\n        return cursor.toArray();\n    }\n}\n\nmodule.exports.Database = Database;\n"]}