edgedb-js icon indicating copy to clipboard operation
edgedb-js copied to clipboard

Query builder: globals

Open colinhacks opened this issue 3 years ago • 3 comments

Proposed API: expose a top-level e.global object containing references. This global object would be created in every module that includes 1+ globals.

e.global.user_id;
e.my_module.global.foo;

More succinct and better autocompletion than e.global("user_id")

Is an implementation of setnecessary or will this be abstracted away by the client API?

e.set(e.global.user_id, e.uuid_generate_v1mc());

// possible method form
e.global.user_id.set(e.uuid_generate_v1mc());

colinhacks avatar May 06 '22 23:05 colinhacks

Hm, I'm not sure why we need this. The proposed global state client API works at the client connection level, not at the qb level:

session = client.withGlobals({user_id: my_user_id})

...

return await session.run(query)

1st1 avatar May 06 '22 23:05 1st1

Is an implementation of set necessary or will this be abstracted away by the client API?

That's why I asked this ☝️

But we still need a way to reference global variables in queries, no?

colinhacks avatar May 07 '22 00:05 colinhacks

That's why I asked this ☝️

Got it :) Yeah, I was mostly talking about e.set() -- don't think we need it that much.

But we still need a way to reference global variables in queries, no?

For that e.globals.xxx should work. Agree that it's better than calling a function. Globals should "feel" like variables.

1st1 avatar May 07 '22 00:05 1st1