feathersjs SQL Raw Query

16 days ago

0) npm install sequelize

1) create CUSTOM SERVICE – first create a sequelize service! these two steps can probably be COMBINED.

2) edit ./src/sequelize.js change logging false to logging true

3) change: src/services/my-custom-service/my-custom-service.class.js :

/* eslint-disable no-unused-vars */
const { QueryTypes } = require(‘sequelize’);

exports.MyCustomService = class MyCustomService { constructor (options, app) { this.options = options || {}; this.app = app; }

############### FIND FIND FIND FIND FIND FIND FIND async find (key) { const sequelize = this.app.get(‘sequelizeClient’); const stimwordPositionSelectFind = ‘SELECT * FROM stimwordPosition WHERE 1 AND stimwordPositionWord = $stimwordPositionWord;’ ; const stimwordPositionSelectParms = { ‘stimwordPositionWord’ : JSON.parse(key.query).stimwordPositionWord } ; const rows = await sequelize.query ( stimwordPositionSelectFind , { ‘bind’ : stimwordPositionSelectParms } ); return rows; } };

browser-console:

async function stimwordPositionFind(param) { console.log( ‘param: ‘ + param); let getResult = await app.service(‘my-custom-service’).find(param); console.log(‘stimwordPosition function: ‘ + JSON.stringify(getResult) ); return getResult;
};
let stimwordPositionResult = null;
let key = { ‘query’ : JSON.stringify( { ‘stimwordPositionWord’ : ‘horse’, ‘parm2’ : ‘answer2’ } ) } ;
stimwordPositionFind(key).then( value => { /* get(GET) */ stimwordPositionResult = value; console.log(‘stimwordPosition(’ + key + ‘) : ‘ + JSON.stringify(stimwordPositionResult) );
});

in browser console:

[ ‘//cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js’
, ‘//unpkg.com/@feathersjs/client@^3.0.0/dist/feathers.js’
].forEach( (src) => { let script = document.createElement(‘script’); script.src = src; script.async = false; document.head.appendChild(script);
});

const app = feathers(); const socket = io(); app.configure(feathers.socketio(socket));

async function stimwordPosition(id) { /* get(GET) (just one by index) */ console.log( ‘id: ‘ + id); let getResult = await app.service(‘my-custom-service’).find(id); console.log(‘stimwordPosition function: ‘ + JSON.stringify(getResult) ); return getResult;
};

############ GET GET GET GET GET GET

async get (id) { const sequelize = this.app.get(‘sequelizeClient’); const stimwordPositionSelectGet = `SELECT * FROM stimwordPosition WHERE 1 AND stimwordPositionAutoIncr = ${id};`; const rows = await sequelize.query(stimwordPositionSelectGet); return rows; }

async function stimwordPosition(id) { /* get(GET) (just one by index) */ console.log( ‘id: ‘ + id); let getResult = await app.service(‘my-custom-service’).get(id); console.log(‘stimwordPosition function: ‘ + JSON.stringify(getResult) ); return getResult;
};
let stimwordPositionResult = null; let key = 1; // assuming your row ID is one
stimwordPosition(key).then( value => { /* get(GET) */ stimwordPositionResult = value; console.log(‘stimwordPosition(’ + key + ‘) : ‘ + JSON.stringify(stimwordPositionResult) );
});
#####################################################

let stimwordPositionResult = null; let key = 1; // assuming your row ID is one
stimwordPosition(key).then( value => { /* get(GET) */ stimwordPositionResult = value; console.log(‘stimwordPosition(’ + key + ‘) : ‘ + JSON.stringify(stimwordPositionResult) );
});

/notice object starting with “query” for the find: let stimwordPositionResult = null; let key = { ‘query’ : ‘horse’ } ; // assuming your row ID is one stimwordPositionFind(key).then( value => { /* get(GET) */ stimwordPositionResult = value; console.log(‘stimwordPosition(’ + key + ‘) : ‘ + JSON.stringify(stimwordPositionResult) ); });
Mark Edwards

,

---

bash reading file using IFS read loop

27 days ago

the problem was trying to get the variables to process outside of the subshell, otherwise the value was not preserved!

https://unix.stackexchange.com/questions/16990/using-data-read-from-a-pipe-instead-than-from-a-file-in-command-options

https://stackoverflow.com/questions/69339514/saving-values-in-bash-shell-variables-while-using-tee

  1. cat test.txt:
    first example line one
    first example line two
    first example line three
    second example line one
    second example line two
  1. test.bsh:
    first=0;
    second=0;
    #while read -r line; do
    while IFS=’‘ read -r line; do [[ $line *'first example'* ]] && ((++first)) [[ $line ‘second example’ ]] && ((++second))
    done < <(cat test.txt;) ## notice passing in command results using <() syntax.

echo $first ## should display 3
echo $second ## should display 2

Mark Edwards

,

---

Javascript chained promises

57 days ago

// ======================================================

// ** 2021-09-14 10:47 AM return promise(dot)then example **

const promiseA = (parm) => { return new Promise( (resolve, reject) => { setTimeout( () => { resolve(“promise-A “ + parm); }, 1000 ); });
}

const promiseB = (parm) => { return new Promise( (resolve, reject) => { setTimeout( () => { resolve(“promise-B “ + parm); }, 2000 ); });
}

const promiseC = (parm) => { return new Promise( (resolve, reject) => { setTimeout( () => { resolve(“promise-C “ + parm); }, 3000 ); });
}

function getExample(initialParms) { /* notice Promise-dot-then-dot-catch usage, NOT async/await usage */ // locally scoped const results = {};

return promiseA(initialParms) .then ( (resultA) => { // add value to results object results.a = resultA; // pass result of this promise to next promise return promiseB(resultA); } ) .then ( (resultB) => { results.b = resultB; return promiseC(resultB); } ) .then ( (resultC) => { results.c = resultC; // results object now contains all values from promise chain return Promise.resolve(results); } ) .catch ( (error) => { return Promise.reject(error); } ) ;
}

let marksResults ; getExample(‘first parms entered’).then( (finalResults) => { marksResults = finalResults } ) ;

// =======================================================

// ** 2021-09-13 3:00 PM async/await example **

const promiseA = (parm) => { return new Promise((resolve, reject) => { setTimeout(resolve, 0500, ‘promise A ‘ + parm); }) };

const promiseB = (parm) => { return new Promise((resolve, reject) => { setTimeout(resolve, 0500, ‘promise B ‘ + parm); }) };

async function getExample(parm) { /* notice async/await usage, not Promise-dot-then-dot-catch usage */ let resultA = await promiseA(parm); console.log(‘first: ‘ + resultA); // some processing let resultB = await promiseB( parm + ‘-’ + resultA ); console.log(‘second: ‘ + resultB); // more processing return resultB // something using both resultA and resultB
}

let final ; getExample(‘123’).then ( (xx) => { final = xx ; } )

// =====================================================

// ** 2021-09-13 10am Promises.all example where parameters are not passed **

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

my own example of “Promises.all”:

const promise1 = new Promise((resolve, reject) => { setTimeout(resolve( ‘promise one’), 0500 ); }); // notice different way for parm!
const promise2 = new Promise((resolve, reject) => { setTimeout(resolve, 6000, ‘promise two’); });
const promise3 = new Promise((resolve, reject) => { setTimeout(resolve, 8000, ‘promise three’); });

Promise.all([promise1, promise2, promise3]) .then ((values) => { console.log(values); }) .finally((values) => { console.log(‘here!’); }) ;

// ================================================================================

Chained Promises:

const myPromise = new Promise((resolve, reject) => { setTimeout(() => { resolve(‘foo’); }, 300);
});

myPromise .then(value => { return value + ‘ and bar’; }) .then(value => { return value + ‘ and bar again’; }) .then(value => { return value + ‘ and again’; }) .then(value => { return value + ‘ and again’; }) .then(value => { console.log(‘value: ‘ + value) }) .catch(err => { console.log(err) });

https://www.mariokandut.com/how-to-wait-for-multiple-promises-in-node-javascript/
How to use Promise.all
const all = Promise.all([ new Promise((resolve, reject) => setTimeout(() => resolve(1), 1000), ), new Promise((resolve, reject) => setTimeout(() => resolve(2), 2000), ), new Promise((resolve, reject) => setTimeout(() => resolve(3), 3000), ),
]).catch(err => console.log(‘Promise was rejected!’, err));

all.then(results => console.log(results)); // the output is: [1, 2, 3]

https://stackoverflow.com/questions/28250680/how-do-i-access-previous-promise-results-in-a-then-chain
A less harsh spin on “Mutable contextual state”
function getExample(){ //locally scoped const results = {}; return promiseA(paramsA).then(function(resultA){ results.a = resultA; return promiseB(paramsB); }).then(function(resultB){ results.b = resultB; return promiseC(paramsC); }).then(function(resultC){ //Resolve with composite of all promises return Promise.resolve(results.a + results.b + resultC); }).catch(function(error){ return Promise.reject(error); });
}

Mark Edwards

,

---

open up google-vm ports

100 days ago

UPDATE: target tag does not seem to work, but "Apply to all" does!

I have had great difficulty getting google-vm to open a port.

my big "struggle/mistake" was the name of the network "target" - it should be "Apply to all".

This value should either be "Apply to all" (or MAYBE specify the name of the google-vm??)

this article is very comprehensive
https://docs.bitnami.com/google/faq/administration/use-firewall/


it proves a little "tricky" to get to the network area:


this is where it HAS to say "Apply to all": (i never did get the target-name working!)


EASY PORT TEST!

ON SERVER:
 ls -l | ncat  -l  10000 ;   ## this simple example will pass the results of the "ls" command out port 10000 then exit.


ON CLIENT:
 telnet  10.128.15.223  10000; ## this client command should display the directory contents then exit.
ncat examples

To display open server ports:
netstat --listening  --numeric  --tcp  --udp;  ## displays open ports
netstat --listening  --numeric  --tcp  --udp;  ## displays open ports (deprecated)


EDIT: 2021-10-14

i forgot about the "target" and to set 0.0.0.0/0
Mark Edwards

,

---

zfs on Rocky-Linux

108 days ago

John Q:

That looks like lvm, which is a fine method. I’ve used lvm in the past, and don’t have any complaints on it except I prefer zfs over lvm.

dnf localinstall https://zfsonlinux.org/epel/zfs-release.el8_4.noarch.rpm ;
gpg —import —import-options show-only /etc/pki/rpm-gpg/RPM-GPG-KEY-zfsonlinux ;
dnf config-manager —disable zfs ;
dnf config-manager —enable zfs-kmod ;
dnf install zfs ;
zpool create test raidz sdb sdc sdd sde ;

untested, i am not sure using zfs is worth the trouble.

reference:
https://openzfs.github.io/openzfs-docs/Getting%20Started/RHEL%20and%20CentOS.html
https://linuxhint.com/install-zfs-centos7/
https://blog.eldernode.com/install-zfs-file-on-centos-8/

Mark Edwards

,

---

« Older

Manage