How to use db.destroy method in qawolf

Best JavaScript code snippet using qawolf

standardCode.ts

Source:standardCode.ts Github

copy

Full Screen

...15 .catch(error => {16 res.send({ ok: false, error: error })17 })18 .finally(() => {19 db.destroy();20 });21});22router.get('/labeler-types', (req, res, next) => {23 let db = req.db;24 stdCode.getLabelerTypes(db)25 .then((results: any) => {26 res.send({ ok: true, rows: results });27 })28 .catch(error => {29 res.send({ ok: false, error: error })30 })31 .finally(() => {32 db.destroy();33 });34});35router.get('/countries', (req, res, next) => {36 let db = req.db;37 stdCode.getCountries(db)38 .then((results: any) => {39 res.send({ ok: true, rows: results });40 })41 .catch(error => {42 res.send({ ok: false, error: error })43 })44 .finally(() => {45 db.destroy();46 });47});48router.get('/changwat', (req, res, next) => {49 let db = req.db;50 stdCode.getChangwat(db)51 .then((results: any) => {52 res.send({ ok: true, rows: results });53 })54 .catch(error => {55 res.send({ ok: false, error: error })56 })57 .finally(() => {58 db.destroy();59 });60});61router.post('/ampur', (req, res, next) => {62 let db = req.db;63 let changwatCode: any = req.body.changwatCode;64 stdCode.getAmpur(db, changwatCode)65 .then((results: any) => {66 res.send({ ok: true, rows: results });67 })68 .catch(error => {69 res.send({ ok: false, error: error })70 })71 .finally(() => {72 db.destroy();73 });74});75router.post('/tambon', (req, res, next) => {76 let db = req.db;77 let changwatCode: any = req.body.changwatCode;78 let ampurCode: any = req.body.ampurCode;79 stdCode.getTambon(db, ampurCode, changwatCode)80 .then((results: any) => {81 res.send({ ok: true, rows: results });82 })83 .catch(error => {84 res.send({ ok: false, error: error })85 })86 .finally(() => {87 db.destroy();88 });89});90router.get('/generic-types', (req, res, next) => {91 let db = req.db;92 stdCode.getGenericTypes(db)93 .then((results: any) => {94 res.send({ ok: true, rows: results });95 })96 .catch(error => {97 res.send({ ok: false, error: error })98 })99 .finally(() => {100 db.destroy();101 });102});103router.get('/type-product', async (req, res, next) => {104 let db = req.db;105 try {106 let rs: any = await stdCode.getGenericHospType(db);107 res.send({ ok: true, rows: rs });108 } catch (error) {109 console.log(error);110 res.send({ ok: false, error: error.message });111 } finally {112 db.destroy();113 }114});115router.get('/generic-type-lv1', (req, res, next) => {116 let db = req.db;117 stdCode.getGenericTypeLV1(db)118 .then((results: any) => {119 res.send({ ok: true, rows: results });120 })121 .catch(error => {122 res.send({ ok: false, error: error })123 })124 .finally(() => {125 db.destroy();126 });127});128router.get('/generic-type-lv2', (req, res, next) => {129 let db = req.db;130 let genericTypeLV1Id: any = req.query.genericTypeLV1Id;131 stdCode.getGenericTypeLV2(db, genericTypeLV1Id)132 .then((results: any) => {133 res.send({ ok: true, rows: results });134 })135 .catch(error => {136 res.send({ ok: false, error: error })137 })138 .finally(() => {139 db.destroy();140 });141});142router.get('/generic-type-lv3', (req, res, next) => {143 let db = req.db;144 let genericTypeLV2Id: any = req.query.genericTypeLV2Id;145 let genericTypeLV1Id: any = req.query.genericTypeLV1Id;146 stdCode.getGenericTypeLV3(db, genericTypeLV1Id, genericTypeLV2Id)147 .then((results: any) => {148 res.send({ ok: true, rows: results });149 })150 .catch(error => {151 res.send({ ok: false, error: error })152 })153 .finally(() => {154 db.destroy();155 });156});157router.get('/generic-types/lv1', co(async (req, res, next) => {158 let db = req.db;159 try {160 let productGroups = req.decoded.generic_type_id;161 let _pgs = [];162 if (productGroups) {163 let pgs = productGroups.split(',');164 pgs.forEach(v => {165 _pgs.push(v);166 });167 }168 let rs = await stdCode.getGenericTypesLV1(db, _pgs);169 res.send({ ok: true, rows: rs });170 } catch (error) {171 console.log(error);172 res.send({ ok: false, error: error.message });173 } finally {174 db.destroy();175 }176}));177router.get('/generic-types/lv2', co(async (req, res, next) => {178 let db = req.db;179 const genericTypeLV1Id: any = req.query.genericTypeLV1Id == 'null' ? null : req.query.genericTypeLV1Id;180 try {181 let _genericTypeLV1Id = req.decoded.generic_type_id;182 let _genericTypeLV2Id = req.decoded.generic_type_lv2_id;183 let v1: any = [];184 let v2: any = [];185 if (_genericTypeLV1Id) {186 v1 = _genericTypeLV1Id.split(',');187 } else {188 v1 = [];189 }190 if (_genericTypeLV2Id) {191 v2 = _genericTypeLV2Id.split(',');192 } else {193 v2 = [];194 }195 let rs = await stdCode.getGenericTypesLV2(db, genericTypeLV1Id, v1, v2);196 res.send({ ok: true, rows: rs });197 } catch (error) {198 console.log(error);199 res.send({ ok: false, error: error.message });200 } finally {201 db.destroy();202 }203}));204router.get('/generic-types/lv3', co(async (req, res, next) => {205 let db = req.db;206 const genericTypeLV1Id: any = req.query.genericTypeLV1Id == 'null' ? null : req.query.genericTypeLV1Id;207 const genericTypeLV2Id: any = req.query.genericTypeLV2Id == 'null' ? null : req.query.genericTypeLV2Id;208 try {209 let _genericTypeLV1Id = req.decoded.generic_type_id;210 let _genericTypeLV2Id = req.decoded.generic_type_lv2_id;211 let _genericTypeLV3Id = req.decoded.generic_type_lv3_id;212 let v1: any = [];213 let v2: any = [];214 let v3: any = [];215 if (_genericTypeLV1Id) {216 v1 = _genericTypeLV1Id.split(',');217 } else {218 v1 = [];219 }220 if (_genericTypeLV2Id) {221 v2 = _genericTypeLV2Id.split(',');222 } else {223 v2 = [];224 }225 if (_genericTypeLV3Id) {226 v3 = _genericTypeLV3Id.split(',');227 } else {228 v3 = [];229 }230 let rs = await stdCode.getGenericTypesLV3(db, genericTypeLV1Id, genericTypeLV2Id, v1, v2, v3);231 res.send({ ok: true, rows: rs });232 } catch (error) {233 console.log(error);234 res.send({ ok: false, error: error.message });235 } finally {236 db.destroy();237 }238}));239router.get('/generic-groups/1', (req, res, next) => {240 let db = req.db;241 stdCode.getGenericGroups1(db)242 .then((results: any) => {243 res.send({ ok: true, rows: results });244 })245 .catch(error => {246 res.send({ ok: false, error: error })247 })248 .finally(() => {249 db.destroy();250 });251});252router.get('/generic-groups/2', (req, res, next) => {253 let db = req.db;254 let groupCode1: any = req.query.groupCode1;255 stdCode.getGenericGroups2(db, groupCode1)256 .then((results: any) => {257 res.send({ ok: true, rows: results });258 })259 .catch(error => {260 res.send({ ok: false, error: error })261 })262 .finally(() => {263 db.destroy();264 });265});266router.get('/generic-groups/3', (req, res, next) => {267 let db = req.db;268 let groupCode1: any = req.query.groupCode1;269 let groupCode2: any = req.query.groupCode2;270 stdCode.getGenericGroups3(db, groupCode1, groupCode2)271 .then((results: any) => {272 res.send({ ok: true, rows: results });273 })274 .catch(error => {275 res.send({ ok: false, error: error })276 })277 .finally(() => {278 db.destroy();279 });280});281router.get('/generic-groups/4', (req, res, next) => {282 let db = req.db;283 let groupCode1: any = req.query.groupCode1;284 let groupCode2: any = req.query.groupCode2;285 let groupCode3: any = req.query.groupCode3;286 stdCode.getGenericGroups4(db, groupCode1, groupCode2, groupCode3)287 .then((results: any) => {288 res.send({ ok: true, rows: results });289 })290 .catch(error => {291 res.send({ ok: false, error: error })292 })293 .finally(() => {294 db.destroy();295 });296});297router.get('/generic-dosages', (req, res, next) => {298 let db = req.db;299 stdCode.getGenericDosage(db)300 .then((results: any) => {301 res.send({ ok: true, rows: results });302 })303 .catch(error => {304 res.send({ ok: false, error: error })305 })306 .finally(() => {307 db.destroy();308 });309});310router.get('/warehouses', (req, res, next) => {311 let db = req.db;312 stdCode.getWarehouseList(db)313 .then((results: any) => {314 res.send({ ok: true, rows: results });315 })316 .catch(error => {317 res.send({ ok: false, error: error })318 })319 .finally(() => {320 db.destroy();321 });322});323router.get('/search/warehouses', (req, res, next) => {324 let db = req.db;325 let _query: any = req.query.query;326 stdCode.getWarehouseSearch(db, _query)327 .then((results: any) => {328 res.send({ ok: true, rows: results });329 })330 .catch(error => {331 res.send({ ok: false, error: error })332 })333 .finally(() => {334 db.destroy();335 });336});337router.get('/search/generics', (req, res, next) => {338 let db = req.db;339 let _query: any = req.query2.query;340 let warehouseId: any = req.query.warehouseId;341 stdCode.searchPlanningByWarehouse(db, warehouseId, _query)342 .then((results: any) => {343 res.send({ ok: true, rows: results });344 })345 .catch(error => {346 res.send({ ok: false, error: error })347 })348 .finally(() => {349 db.destroy();350 });351});352router.get('/product-groups', async (req, res, next) => {353 let db = req.db;354 try {355 let rs: any = await stdCode.getProductGroups(db);356 res.send({ ok: true, rows: rs });357 } catch (error) {358 console.log(error);359 res.send({ ok: false, error: error.message });360 } finally {361 db.destroy();362 }363});364router.get('/ed', async (req, res, next) => {365 let db = req.db;366 try {367 let rs: any = await stdCode.getED(db);368 res.send({ ok: true, rows: rs });369 } catch (error) {370 console.log(error);371 res.send({ ok: false, error: error.message });372 } finally {373 db.destroy();374 }375});376router.get('/generic-accounts', co(async (req, res, next) => {377 let db = req.db;378 try {379 let rs: any = await stdCode.getGenericAccounts(db)380 res.send({ ok: true, rows: rs });381 } catch (error) {382 res.send({ ok: false, error: error.message });383 } finally {384 db.destroy();385 }386}));387router.get('/bid-types', co(async (req, res, next) => {388 let db = req.db;389 try {390 let rs: any = await stdCode.getBitTypes(db)391 res.send({ ok: true, rows: rs });392 } catch (error) {393 res.send({ ok: false, error: error.message });394 } finally {395 db.destroy();396 }397}));398router.get('/type-product', co(async (req, res, next) => {399 let db = req.db;400 try {401 let rs: any = await stdCode.getProductType(db)402 res.send({ ok: true, rows: rs });403 } catch (error) {404 res.send({ ok: false, error: error.message });405 } finally {406 db.destroy();407 }408}));...

Full Screen

Full Screen

server.spec.js

Source:server.spec.js Github

copy

Full Screen

...123 ]);124 expect(res.rows.length).to.equal(7);125 })126 .then(() => {127 return db.destroy();128 })129 .then(() => {130 done();131 })132 .catch((err) => {133 expect(err).to.be.null;134 db.destroy()135 .then(() => {136 done();137 });138 });139 });140 xit('Creates a new table in database', function(done) {141 db.raw("CREATE TABLE items(id SERIAL PRIMARY KEY, text VARCHAR(40) not null, complete BOOLEAN);")142 .then((res) => {143 db.raw("SELECT * FROM items")144 .then((res) => {145 db.raw("DROP table items;")146 .then((res) => {147 db.destroy();148 done();149 })150 .catch((err) => {151 expect(err).to.be.null;152 db.destroy();153 done();154 })155 })156 .catch((err) => {157 expect(err).to.be.null;158 db.destroy();159 done();160 })161 })162 .catch((err) => {163 expect(err).to.be.null;164 db.destroy();165 done();166 });167 });168 });169 describe('Media Model: ', function() {170 //Unit Tests171 xit('Should have a function called uploadToPG', function() {172 expect(mediaModel.uploadToPG).to.be.a('function');173 });174 xit('Should have a function called uploadToS3', function() {175 expect(mediaModel.uploadToS3).to.be.a('function');176 });177 xit('Should have a function called updatePGid', function() {178 expect(mediaModel.updatePGid).to.be.a('function');179 });180 xit('Should have a function called retrievePhotosFromPG', function() {181 expect(mediaModel.retrievePhotosFromPG).to.be.a('function');182 });183 xit('Should have a function called deletePhotoByIdPG', function() {184 expect(mediaModel.deletePhotoByIdPG).to.be.a('function');185 });186 xit('Should have a function called deletePhotoByIdS3', function() {187 expect(mediaModel.deletePhotoByIdS3).to.be.a('function');188 });189 //Writing to DB Tests190 xit('Should retrieve photos information from PostgreSQL', function(done) {191 mediaModel.retrievePhotosFromPG()192 .then(function (data) {193 expect(data).to.have.property('rowCount');194 db.destroy()195 done();196 })197 .catch(function (err) {198 expect(err).to.be.null;199 db.destroy();200 done();201 })202 });203 xit('Should upload photo metaData to PostgreSQL', function(done) {204 var sampleData = {205 user: 3,206 url_small: 'url789_small',207 url_med: 'url789_medium',208 url_large: 'url789_large',209 title: 'MegansPhoto',210 description: 'ImFancy'211 };212 mediaModel.uploadToPG(sampleData)213 .then(function(data){214 expect(data.rowCount).to.equal(1);215 done();216 })217 .catch((err) => {218 done();219 });220 });221 xit('Should upload a string to S3 and return a string', function(done) {222 mediaModel.uploadToS3(22, "TEST_STRING")223 .then(function(data) {224 expect(data.ETag).to.be.a('string');225 done();226 })227 .catch(function(err) {228 expect(err).to.be.null;229 done();230 });231 });232 xit('Should upload a photo buffer to S3', function(done) {233 var photoBuff = (__dirname + './circus.jpg');234 mediaModel.uploadToS3(40, photoBuff)235 .then(function(photoId){236 expect(photoId.ETag).to.be.a('string');237 done();238 })239 .catch((err) => {240 expect(err).to.be.null;241 done();242 });243 });244 xit('Should update photos urls to PostgreSQL', function(done) {245 mediaModel.updatePGid(['url123_medium', 'url123_large'], 121)246 .then(function(data) {247 expect(data).to.be.a('object');248 // db.destroy();249 done();250 })251 .catch(function(err) {252 // expect(err).to.be.null;253 // db.destroy();254 done(err);255 });256 });257 xit('Should delete photos from S3 database', function(done) {258 mediaModel.deletePhotoByIdS3(621)259 .then(function(data) {260 expect(data).to.be.a('object');261 // db.destroy();262 done();263 })264 .catch(function(err) {265 expect(err).to.be.null;266 // db.destroy();267 done(err);268 });269 });270 xit('Should delete photo record from PostgreSQL database', function(done) {271 mediaModel.deletePhotoByIdPG(617)272 .then(function(data) {273 console.log(data);274 expect(data).to.be.a('object');275 // db.destroy();276 done();277 })278 .catch(function(err) {279 expect(err).to.be.null;280 // db.destroy();281 done(err);282 });283 });284 });285 describe('MediaTags Model: ', function() {286 xit('Should associate tags with a given photo', function(done) {287 metaTags.insert(['funny', 'circus', 'canon', 'cartoon'], 121)288 .then(function(data) {289 expect(data).to.be.a('object');290 expect(data.rows[0]).to.have.property('id');291 // db.destroy();292 done();293 })294 .catch(function(err) {295 expect(err).to.be.null;296 // db.destroy();297 done(err);298 });299 });300 });301 describe('Media Controller: ', function() {302 xit('Should have a function called uploadPhoto', function() {303 expect(mediaController.uploadPhoto).to.be.a('function');304 });305 xit('Should have a function called getPhotos', function() {306 expect(mediaController.getPhotos).to.be.a('function');307 });308 });309 });310});

Full Screen

Full Screen

test.defaults.js

Source:test.defaults.js Github

copy

Full Screen

...28 prefix: prefix29 }).then(function (db) {30 return db.info().then(function (info1) {31 info1.db_name.should.equal('mydb');32 return db.destroy();33 });34 });35 });36 it('should allow us to set a prefix by default', function () {37 var prefix = './tmp/path/to/db/2/';38 var dir = path.join(prefix, '/tmp/');39 var dir2 = path.join('./tmp/_pouch_./', prefix);40 var dir3 = path.join(dir2, './tmp/_pouch_mydb');41 mkdirp.sync(dir);42 mkdirp.sync(dir2);43 mkdirp.sync(dir3);44 var CustomPouch = PouchDB.defaults({45 prefix: prefix46 });47 /* jshint newcap:false */48 var db = CustomPouch({name: 'mydb'});49 return db.info().then(function (info1) {50 info1.db_name.should.equal('mydb');51 return db.destroy();52 });53 });54 it('should allow us to use memdown', function () {55 var opts = { name: 'mydb', db: require('memdown') };56 return new PouchDB(opts).then(function (db) {57 return db.put({_id: 'foo'}).then(function () {58 return new PouchDB('mydb').then(function (otherDB) {59 return db.info().then(function (info1) {60 return otherDB.info().then(function (info2) {61 info1.doc_count.should.not.equal(info2.doc_count);62 return otherDB.destroy();63 }).then(function () {64 return db.destroy();65 });66 });67 });68 });69 });70 });71 it('should allow us to destroy memdown', function () {72 var opts = {db: require('memdown') };73 return new PouchDB('mydb', opts).then(function (db) {74 return db.put({_id: 'foo'}).then(function () {75 return new PouchDB('mydb', opts).then(function (otherDB) {76 return db.info().then(function (info1) {77 return otherDB.info().then(function (info2) {78 info1.doc_count.should.equal(info2.doc_count);79 return otherDB.destroy();80 }).then(function () {81 return new PouchDB('mydb', opts).then(function (db3) {82 return db3.info().then(function (info) {83 info.doc_count.should.equal(0);84 return db3.destroy();85 });86 });87 });88 });89 });90 });91 });92 });93 it('should allow us to use memdown by default', function () {94 var CustomPouch = PouchDB.defaults({db: require('memdown')});95 return new CustomPouch('mydb').then(function (db) {96 return db.put({_id: 'foo'}).then(function () {97 return new PouchDB('mydb').then(function (otherDB) {98 return db.info().then(function (info1) {99 return otherDB.info().then(function (info2) {100 info1.doc_count.should.not.equal(info2.doc_count);101 return otherDB.destroy();102 }).then(function () {103 return db.destroy();104 });105 });106 });107 });108 });109 });110 it('should inform us when using memdown', function () {111 var opts = { name: 'mydb', db: require('memdown') };112 return new PouchDB(opts).then(function (db) {113 return db.info().then(function (info) {114 info.backend_adapter.should.equal('MemDOWN');115 });116 });117 });118 it('constructor emits destroyed when using defaults', function () {119 var CustomPouch = PouchDB.defaults({db: require('memdown')});120 return new CustomPouch('mydb').then(function (db) {121 return new PouchDB.utils.Promise(function (resolve) {122 CustomPouch.once('destroyed', function (name) {123 name.should.equal('mydb');124 resolve();125 });126 db.destroy();127 });128 });129 });130 it('db emits destroyed when using defaults', function () {131 var CustomPouch = PouchDB.defaults({db: require('memdown')});132 return new CustomPouch('mydb').then(function (db) {133 return new PouchDB.utils.Promise(function (resolve) {134 db.once('destroyed', resolve);135 db.destroy();136 });137 });138 });139 it('constructor emits creation event', function (done) {140 var CustomPouch = PouchDB.defaults({db: require('memdown')});141 CustomPouch.once('created', function (name) {142 name.should.equal('mydb', 'should be same thing');143 done();144 });145 new PouchDB('mydb');146 });147 // somewhat odd behavior (CustomPouch constructor always mirrors PouchDB),148 // but better to test it explicitly149 it('PouchDB emits destroyed when using defaults', function () {150 var CustomPouch = PouchDB.defaults({db: require('memdown')});151 return new CustomPouch('mydb').then(function (db) {152 return new PouchDB.utils.Promise(function (resolve) {153 PouchDB.once('destroyed', function (name) {154 name.should.equal('mydb');155 resolve();156 });157 db.destroy();158 });159 });160 });161 // somewhat odd behavior (CustomPouch constructor always mirrors PouchDB),162 // but better to test it explicitly163 it('PouchDB emits created when using defaults', function (done) {164 var CustomPouch = PouchDB.defaults({db: require('memdown')});165 PouchDB.once('created', function (name) {166 name.should.equal('mydb', 'should be same thing');167 done();168 });169 new CustomPouch('mydb');170 });171 });...

Full Screen

Full Screen

api_mysql.js

Source:api_mysql.js Github

copy

Full Screen

...19 table.string("title", 20).notNullable();20 table.decimal("price", 6, 2).notNullable();21 table.string("thumbnail", 255).notNullable();22 });23 db.destroy();24 exampleProducts.forEach(async (prod) => {25 await this.addNewProduct(prod);26 });27 return {28 status: 200,29 content: { success: `Tabla ${newTable} creada` },30 };31 } else {32 db.destroy();33 return {34 status: 200,35 content: { success: `No se requiere crear la tabla ${newTable}` },36 };37 }38 } catch (err) {39 db.destroy();40 return { status: 500, content: err };41 }42 }43 async getProducts() {44 try {45 const db = this.#createMySQL();46 let products = await db.select().from(this.table);47 if (products.length > 0) {48 db.destroy();49 return { status: 200, content: products };50 } else {51 db.destroy();52 return {53 status: 200,54 content: { error: `No hay productos a mostrar` },55 };56 }57 } catch (err) {58 db.destroy();59 return { status: 500, content: { error: `${err}` } };60 }61 }62 async getProductById(id) {63 try {64 if (!isNaN(parseInt(id))) {65 const db = this.#createMySQL();66 const selectedProduct = await db(this.table).where("id", id);67 db.destroy();68 return selectedProduct != undefined && selectedProduct != null69 ? { status: 200, content: selectedProduct[0] }70 : { status: 200, content: { error: `Producto no encontrado` } };71 } else {72 return { status: 400, content: { error: `Error en la petición` } };73 }74 } catch (err) {75 return { status: 500, content: err };76 }77 }78 async delProductById(id) {79 try {80 if (!isNaN(parseInt(id))) {81 const db = this.#createMySQL();82 let del = await db(this.table).where("id", id).del();83 if (del == 1) {84 db.destroy();85 return {86 status: 200,87 content: { success: `Producto con ID: ${id} borrado` },88 };89 } else {90 db.destroy();91 return { status: 200, content: { error: `Producto no encontrado` } };92 }93 } else {94 return { status: 400, content: { error: `Error en la petición` } };95 }96 } catch (err) {97 return { status: 500, content: err };98 }99 }100 async addNewProduct(product) {101 try {102 if (103 product.title &&104 !isNaN(parseFloat(product.price)) &&105 product.thumbnail106 ) {107 const db = this.#createMySQL();108 let newId = await db(this.table).insert(product);109 let newProduct = JSON.parse(110 JSON.stringify(await this.getProductById(newId))111 );112 db.destroy();113 return { status: 200, content: newProduct.content };114 } else {115 return { status: 400, content: { error: `Error en la petición` } };116 }117 } catch (err) {118 db.destroy();119 return {120 status: 500,121 content: `Error en el servidor: ${err}`,122 };123 }124 }125 async updateProduct(id, product) {126 if (127 !isNaN(parseInt(id)) &&128 product.title &&129 !isNaN(parseFloat(product.price)) &&130 product.thumbnail131 ) {132 try {133 const db = this.#createMySQL();134 if ((await db(this.table).where("id", id).update(product)) == 1) {135 db.destroy();136 return { status: 200, content: { success: `Producto actualizado` } };137 } else {138 db.destroy();139 return { status: 200, content: { error: `Producto no encontrado` } };140 }141 } catch (err) {142 db.destroy();143 return { status: 500, content: { error: err } };144 }145 } else {146 return { status: 400, content: { error: `Error en la petición.` } };147 }148 }149};150module.exports.ChatMsgsMySQLDB = class ChatMsgsDB {151 #knex = require("knex");152 constructor(dbOptions) {153 this.dbOptions = dbOptions;154 this.table = "chatmsgs";155 }156 #createMySQL() {157 return this.#knex(this.dbOptions);158 }159 async createTblChatMsgs(newTable) {160 this.table = newTable;161 try {162 const db = this.#createMySQL();163 const tableExists = await db.schema.hasTable(newTable);164 if (!tableExists) {165 await db.schema.createTable(newTable, (table) => {166 table.increments("id").primary().notNullable();167 table.string("email", 60).notNullable();168 table.datetime("datetime").notNullable();169 table.string("msg", 255).notNullable();170 });171 db.destroy();172 return {173 status: 200,174 content: { success: `Tabla ${newTable} creada` },175 };176 } else {177 db.destroy();178 return {179 status: 200,180 content: { success: `No se requiere crear la tabla ${newTable}` },181 };182 }183 } catch (err) {184 console.log(err);185 db.destroy();186 return { status: 500, content: err };187 }188 }189 async save(data) {190 try {191 data = { ...data };192 const date = require("date-and-time");193 const db = this.#createMySQL();194 data.datetime = date.format(195 new Date(data.datetime),196 "YYYY-MM-DD hh:mm:ss"197 );198 let idMsg = await db(this.table).insert(data);199 db.destroy();200 return { status: 200, content: `Mensaje guardado con ID ${idMsg}` };201 } catch (err) {202 console.log(err);203 db.destroy();204 return { status: 500, content: `Error en el servidor: ${err}` };205 }206 }...

Full Screen

Full Screen

consultas.js

Source:consultas.js Github

copy

Full Screen

1const db = require('../config/db');2// db('perfis')3// .map((p) => p.nome)4// .then(nomes => console.log(nomes))5// .finally(() => db.destroy())6// db('perfis').select('nome', 'id')7// .then(res => console.log(res))8// .finally(() => db.destroy())9// db.select('nome', 'id')10// .from('perfis')11// .limit(4).offset(0)12// .then(res => console.log(res))13// .finally(() => db.destroy())14// db('perfis')15// .select('id', 'nome')16// // .where({ id: 2 })17// // .where('id', '=', 2)18// // .where('nome', 'like', '%m%')19// // .whereNot({ id: 2 })20// .whereIn('id', [1, 2, 3])21// // .first()22// .then(res => console.log(res))23// .finally(() => db.destroy())24db.raw('select * from perfis limit 3')25 .then(res => console.log(res[0]))...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { launch } = require("qawolf");2const selectors = require("../selectors/test");3describe("test", () => {4 let browser;5 beforeAll(async () => {6 });7 afterAll(async () => {8 await browser.close();9 });10 it("test", async () => {11 const page = await browser.newPage();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { create } = require("@qawolf/browser");2const { test, expect } = require("@qawolf/web");3describe("test", () => {4 let browser;5 let page;6 beforeAll(async () => {7 browser = await create();8 });9 afterAll(async () => {10 await browser.close();11 });12 beforeEach(async () => {13 page = await browser.newPage();14 });15 afterEach(async () => {16 await page.close();17 });18 it("test", async () => {19 await page.type("#lst-ib", "test");20 await page.press("#lst-ib", "Enter");21 await page.click("text=Test - Wikipedia");22 await page.click("text=Test - Wikipedia");23 const [page1] = await Promise.all([24 new Promise(resolve => browser.once("targetcreated", target => resolve(target.page()))),25 page.click("text=Test - Wikipedia")26 ]);

Full Screen

Using AI Code Generation

copy

Full Screen

1const qawolf = require("qawolf");2qawolf.create().then(async (browser) => {3 const page = await browser.newPage();4 await page.type("#tsf > div:nth-child(2) > div > div.RNNXgb > div > div.a4bIc > input", "test");5 await page.click("#tsf > div:nth-child(2) > div > div.FPdoLc.VlcLAe > center > input.gNO89b");6 await page.waitForNavigation();7 await page.click("#rso > div:nth-child(1) > div > div > div > div > div > div > div > div > div:nth-child(1) > a > h3");8 await page.waitForNavigation();9 await page.click("#rso > div:nth-child(1) > div > div > div > div > div > div > div > div > div:nth-child(1) > a > h3");10 await page.waitForNavigation();11 await page.click("#rso > div:nth-child(1) > div > div > div > div > div > div > div > div > div:nth-child(1) > a > h3");12 await page.waitForNavigation();13 await page.click("#rso > div:nth-child(1) > div > div > div > div > div > div > div > div > div:nth-child(1) > a > h3");14 await page.waitForNavigation();15 await page.click("#rso > div:nth-child(1) > div > div > div > div > div > div > div > div > div:nth-child(1) > a > h3");16 await page.waitForNavigation();17 await page.click("#rso > div:nth-child(1) > div > div > div > div > div > div > div > div > div:nth-child(1) > a > h3");18 await page.waitForNavigation();19 await page.click("#rso > div:nth-child(1) > div > div > div > div > div > div > div > div > div:nth-child(1) > a > h3");20 await page.waitForNavigation();21 await page.click("#rso > div:nth-child(1) > div > div > div > div > div > div > div > div > div:nth-child

Full Screen

Using AI Code Generation

copy

Full Screen

1const { db } = require('qawolf');2await db.destroy();3const { db } = require('qawolf');4await db.destroy();5const { db } = require('qawolf');6await db.destroy();7const { db } = require('qawolf');8await db.destroy();9const { db } = require('qawolf');10await db.destroy();11const { db } = require('qawolf');12await db.destroy();13const { db } = require('qawolf');14await db.destroy();15const { db } = require('qawolf');16await db.destroy();17const { db } = require('qawolf');18await db.destroy();19const { db } = require('qawolf');20await db.destroy();21const { db } = require('qawolf');22await db.destroy();23const { db }

Full Screen

Using AI Code Generation

copy

Full Screen

1const qawolf = require('qawolf');2const browser = await qawolf.launch();3const page = await browser.newPage();4await page.click('button');5await page.type('input', 'hello world');6await qawolf.stopVideos();7await qawolf.destroy(browser);8const qawolf = require('qawolf');9const browser = await qawolf.launch();10const page = await browser.newPage();11await page.click('button');12await page.type('input', 'hello world');13await qawolf.stopVideos();14await qawolf.create(browser);15const qawolf = require('qawolf');16const browser = await qawolf.launch();17const page = await browser.newPage();18await page.click('button');19await page.type('input', 'hello world');20await qawolf.stopVideos();21await qawolf.create(browser);22const qawolf = require('qawolf');23const browser = await qawolf.launch();24const page = await browser.newPage();25await page.click('button');26await page.type('input', 'hello world');27await qawolf.stopVideos();28await qawolf.create(browser);29const qawolf = require('qawolf');30const browser = await qawolf.launch();31const page = await browser.newPage();32await page.click('button');33await page.type('input', 'hello world');34await qawolf.stopVideos();35await qawolf.create(browser);36const qawolf = require('qawolf');37const browser = await qawolf.launch();38const page = await browser.newPage();39await page.click('button');40await page.type('input', 'hello world');41await qawolf.stopVideos();42await qawolf.create(browser);43const qawolf = require('qawolf');44const browser = await qawolf.launch();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { db } = require("qawolf");2it("should work", async () => {3 const browser = await qawolf.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.click("text=I'm Feeling Lucky");7 await db.create("test", page);8});9it("should work", async () => {10 const browser = await qawolf.launch();11 const context = await browser.newContext();12 const page = await context.newPage();13 await db.destroy("test", page);14});15const { db } = require("qawolf");16it("should work", async () => {17 const browser = await qawolf.launch();18 const context = await browser.newContext();19 const page = await context.newPage();20 await page.click("text=I'm Feeling Lucky");21 await db.create("test", page);22 await db.destroy("test", page);23});

Full Screen

Using AI Code Generation

copy

Full Screen

1await db.destroy();2await db.destroy();3await db.destroy();4await db.destroy();5I want to use db.destroy() method in every test case. Is there any way to call this method before every test case?6const { db } = require('qawolf');7beforeAll(async () => {8 await db.destroy();9});10afterAll(async () => {11 await db.destroy();12});13Thanks for your reply. I am using jest framework for testing. I want to call db.destroy() method before every test case. Is there any way to call this method before every test case?14const { db } = require('qawolf');15beforeAll(async () => {16 await db.destroy();17});18afterAll(async () => {19 await db.destroy();20});21const { db } = require('qawolf');22test('Create new user', async () => {23 const browser = await qawolf.launch();24 const page = await browser.newPage();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run qawolf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful