console.table(variable-name)
console.trace()
console.error() and console.warn()
console.count() and console.countReset()
console.time(), console.timeEnd(), and console.timeLog()
console.clear()
textpattern blog for Marks Notes
Aug 9, 05:31 PM
console.table(variable-name)
console.trace()
console.error() and console.warn()
console.count() and console.countReset()
console.time(), console.timeEnd(), and console.timeLog()
console.clear()
May 11, 03:37 AM
// from https://releases.jquery.com/ ?? do we really need the https: part ???
be SURE to start out with the “about:blank” page — 2022-11-21
[ ‘https://code.jquery.com/jquery-3.6.0.js’
].forEach( (src) => {
let script = document.createElement(‘script’); script.src = src; script.async = false;
document.head.appendChild(script);
});
May 4, 08:22 AM
to remove rule:
stylesheet.deleteRule(index),
(loop to find the right value)
==========================================================
// https://webplatform.github.io/docs/tutorials/Dynamic_style_-_manipulating_CSS_with_JavaScript/
// https://stackoverflow.com/questions/70251599/how-to-use-cssstylesheet-insertrule-to-change-a-root-property/71875353
to manipulate the “—” rules such as “—marksVariableName, it has to be done in the” selector and use insertRule:”
this should turn the background color from red to whatever value is in the hash.Mar 28, 09:33 AM
2022-04-01:
function tryMe({one, two, three}) { console.log(one, two,three) ; }
const tmp = { one: 1, two: 2, three: 3 } ;
tryMe(tmp) ;
=========================================
https://www.sitepoint.com/community/t/promises-feedback/384246/3
consider passing an JSON object for parms in the future:
function tester({param}) {
console.log(JSON.stringify(param));
}
tester({param: { ‘parmOne’: 123, ‘paramTwo’: “two”}}) ;
===========
REPLACE:
function desiredCar(eachCar) {
const make = eachCar.make;
const model = eachCar.model;
const hp = eachCar.hp;
// then do stuff with make, model, and hp
}
WITH:
function desiredCar({make, model, hp}) {
}
=======
Dec 16, 11:36 AM
knex examples to replace sequelize.
first create knex user:
DROP USER IF EXISTS ‘knexUser’@‘localhost’ ;
CREATE USER ‘knexUser’@‘localhost’ IDENTIFIED BY ‘knexPassword’;
GRANT ALL ON `comptonTransAnlys`.* TO ‘knexUser’@‘localhost’
IDENTIFIED BY ‘knexPassword’ WITH MAX_QUERIES_PER_HOUR 0
MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
GRANT ALL PRIVILEGES ON `comptonTransAnlys`.* TO ‘knexUser’@‘localhost’ ;
// https://zetcode.com/javascript/knex/
// mariadb —host=localhost —user=knexUser —password=knexPassword knexDb ;
const knexConnectOptions = {
client: ‘mysql’,
debug: true,
connection: {
host : ‘localhost’,
port : 3306,
user : ‘knexUser’,
password : ‘knexPassword’,
database : ‘knexDb’
}
};
const knex = require(‘knex’)(knexConnectOptions);
knex.raw(“SELECT VERSION”) .then ( (version) => console.log((version00)) ) .catch((err) => { console.log( err); throw err }) .finally(() => { knex.destroy(); });
knex.schema .createTable(‘cars’, (table) => { table.increments(‘id’) ; table.string(‘name’) ; table.integer(‘price’) ; }) .then(() => console.log(“table created”)) .catch((err) => { console.log(err); throw err }) .finally(() => { knex.destroy(); process.exit(); });
const cars = [
{ name: ‘Audi’, price: 52642 },
{ name: ‘Mercedes’, price: 57127 },
{ name: ‘Skoda’, price: 9000 },
{ name: ‘Volvo’, price: 29000 },
{ name: ‘Bentley’, price: 350000 },
{ name: ‘Citroen’, price: 21000 },
{ name: ‘Hummer’, price: 41400 },
{ name: ‘Volkswagen’, price: 21600 },
]
knex.from(‘cars’) // or just knex(‘cars’) .insert(cars) .then((id) => console.log(“data inserted: “ + id ) /* note display of returned ID! */ .catch((err) => { console.log(err); throw err }) .finally(() => { knex.destroy(); process.exit(); });
knex.from(‘cars’) // or just knex(‘cars’) .select(“*”) .where (true) // optional! .then((rows) => { for (row of rows) { console.log(`${row[‘id’]} ${row[‘name’]} ${row[‘price’]}`); } }).catch((err) => { console.log( err); throw err }) .finally(() => { knex.destroy(); process.exit(); });
knex.from(‘cars’) // or just knex(‘cars’) .select(“name”, “price”).where(‘price’, ‘>’, ‘50000’) .where (true) .then((rows) => { for (row of rows) { console.log(`${row[‘name’]} ${row[‘price’]}`); } }) .catch((err) => { console.log( err); throw err }) .finally(() => { knex.destroy(); process.exit(); });
// mariadb —host=localhost —user=knexUser —password=knexPassword knexDb ;
const knexConnectOptions = {
client: ‘mysql’,
debug: true,
connection: ‘mysql://knexUser:knexPassword@localhost:3306/knexDb’
};
const knex = require(‘knex’)(knexConnectOptions);
knex(‘cars’)
.where ({‘id’: 6 }) // OR .where (‘id’ , ‘=’, 6)
.update({ name : ‘Toyota’}) /* notice {} */
.catch((err) => { console.log( err); throw err })
.finally(() => {
knex.destroy();
process.exit();
});
// delete!
knex(‘cars’)
.where (‘id’ , ‘=’, 6)
.del()
.catch((err) => { console.log( err); throw err })
.finally(() => {
knex.destroy();
process.exit();
});
// short connection string:
const knexConnectOptions = {
client: ‘mysql’,
connection: ‘mysql://knexUser:knexPassword@localhost:3306/knexDb’
};
const knex = require(‘knex’)(knexConnectOptions);
knex.from(‘cars’) .select(“name”, “price”) .where(‘id’, ‘=’, ‘6’) .then((rows) => { for (row of rows) { console.log(`${row[‘name’]} ${row[‘price’]}`); } }) .catch((err) => { console.log( err); throw err }) .finally(() => { knex.destroy(); process.exit(); });