How to create a type '[*c]const [*c]const u8' for paramValues of PQexecParams - libpq

I'm trying to use the libpq library in zig. I'm trying to pass paramValues to PQexecParams. I'm just not sure how to create the required type.
The type required by the documentation is:
const char * const *paramValues
So something like:
const char data[2][2] = {"12","me"};
If do something like this in zig:
const paramValues = [_][]const u8 {"12","me"};
I get this error:
error: expected type '[*c]const [*c]const u8', found '[2][]const u8'

Use:
const paramValues = [_][*:0]const u8 {"12","me"};
PQexecParams(....., &paramValues, ....);

Related

Node js - Issue with my syntax in require(module) . When to use {} and when not to use {} in require('module')

I have a query with the syntax in the require statement. Please refere the sample code below.
const nodemailer = require("nodemailer");
const {google} =require('googleapis');
const {OAuth2}=google.auth;
Some times , I see sample codes which use
const {<variable>} = require('moduleName')
Other times, I see like below
const <variable> = require('moduleName')
What is the difference between them?
Thanks in Advance.
Grateful to the Developers Community.
So, you use { } in this context when you want to do object destructuring to get a property from the exported object and create a module-level variable with that same name.
This:
const { google } = require('googleapis');
is a shortcut for this:
const __g = require('googleapis');
const google = __g.google;
So, within this context, you use the { google } only when you want the .google property from the imported module.
If you want the entire module handle such as this:
const nodemailer = require("nodemailer");
then, you don't use the { }. The only way to know which one you want for any given module is to consult the documentation for the module, the code for the module or examples of how to use the module. It depends entirely upon what the module exports and whether you want the top level export object or you want a property of that object.
It's important to realize that the { } used with require() is not special syntax associated with require(). This is normal object destructuring assignment, the same as if you did this:
// define some object
const x = { greeting: "hello" };
// use object destructuring assignment to create a new variable
// that contains the property of an existing object
const { greeting } = x;
console.log(greeting); // "hello
When you import the function with {}, it means you just import one function that available in the package. Maybe you have've seen:
const {googleApi, googleAir, googleWater} = require("googleapis")
But, when you not using {}, it means you import the whole package, just write:
const google = require("googleapis")
So, let say when you need googleApi in your code. You can call it:
google.googleApi

Gremlin Javascript order by function

I use gremlin-javascript (in aws Neptune) to traverse the remote graph and get a list of vertex. I want order the vertex by their createdAt date property. But since I have multiple order().by(), I want to group them by week.
const gremlin = require('gremlin')
const moment = require('moment')
const { Graph } = gremlin.structure
const { DriverRemoteConnection } = gremlin.driver
const __ = gremlin.process.statics
const { order } = gremlin.process
const getWeek = date => parseInt(moment(date).format('YYYYWW'), 10)
const graph = new Graph()
const dc = new DriverRemoteConnection(endpointNeptune)
const g = graph.traversal().withRemote(dc)
g.V().order().by(getWeek(__.values('createdAt')), order.decr)
But this throw an error: "Could not locate method: NeptuneGraphTraversal.by([202029, decr])"
Thank you in advance
Copying my earlier comment to an answer:
The by modulator is expecting a key name not a literal value. Something like
g.V().group().by('createdAt').order(local).by(keys,desc)
or perhaps depending on your data model
g.V().order().by('createdAt', order.desc)

Const not defined in nodejs causing unit tests to fail

Error that I am getting
ReferenceError: LAST_PAYMENT_AMOUNT is not defined
part of nodejs code
const LAST_PAYMENT_AMOUNT = [LAST_PAYMENT_AMOUNT];
const LAST_PAYMENT_DATE = [LAST_PAYMENT_DATE];
const NEXT_PAYMENT_DATE = [NEXT_PAYMENT_DATE];
const accountIntentMap = {
payment_summary_payoff: {
LAST_PAYMENT_AMOUNT: "lastPaymentAmount",
You're trying to access: LAST_PAYMENT_AMOUNT, LAST_PAYMENT_DATE & NEXT_PAYMENT_DATE before initialization.
That code won't work, and doesn't make sense. You probably want to assign something different to each const.

Argument of type '{}' is not assignable to parameter of type 'Uint8Array'

I'm trying to clone and run an opensource project repo and having hard time fixing this issue, npm start fails with "compile failed error' and its states the following reason.
Argument of type '{}' is not assignable to parameter of type 'Uint8Array'
const [encChallenge] = await waitEvent(socket, 'data')
const challenge = decrypt(encChallenge) //This line causes the error
Following in the decrypt function
/** Decrypt data used shared key */
function decrypt(data: Uint8Array) {
if (!sharedKey) return null
const nonce = data.slice(0, sodium.crypto_box_NONCEBYTES)
const box = data.slice(sodium.crypto_box_NONCEBYTES, data.length)
const msg = crypto.decrypt(box, nonce, sharedKey)
return msg
}
Changing the parameter to any solves it but I can't do that,
How can I convert my parameter to Unit8Array?
As long as encChallenge is a typed array represents an array of 8-bit unsigned integers then you should just be able to do:
const [encChallenge] = await waitEvent(socket, 'data')
const challenge = decrypt(new Uint8Array(encChallenge);)
really i would make waitEvent encChallenge be of strongly type Uint8Array in waitEvent method, then it's abstracted away and always that type if you reuse it again.

Moment.js: "TypeError: momentRange.range" when using with moment-range

I have problem using all 3 of the packages together. I define them like this:
var moment = require('moment-timezone');
var momentRange = require('moment-range');
And when I want to use the moment-range functions, I'm trying to call it like this:
var range1 = momentRange.range(moment("string1"), moment("string2"));
And I'm getting error: TypeError: momentRange.range is not a function
What am I doing wrong?
According to the documentation, you are supposed to use the moment-range library to first extend the core moment library itself, then use moment.range because the moment-range package adds additional functions to the moment object:
var momentRange = require('moment-range');
momentRange.extendMoment(moment);
moment.range(moment(…), moment(…)); // Now usable
Specifically, in their documentation:
CommonJS:
const Moment = require('moment');
const MomentRange = require('moment-range');
const moment = MomentRange.extendMoment(Moment);

Resources