Comments (13)
Your guess that the camel casing is interfering with introspection seems to be on the money :) The receive
option can be set after initialization, so you'll want to start looking in the reload
function in lib/database.js to ensure that the driver (this.pgp
) doesn't have it set while the reload is actively going on.
from massive-js.
@dmfay: Thanks for the pointer. I've tried to figure out how to set an option after initialization, but can't seem to suss it out. Would you have a further pointer for that?
(It seems I need to access the $config.options member of the underlying db connection, but that is not the same thing as db.pgp. Constructs like db.pgp.$config don't resolve. I'm probably off the track on how I'm looking for this, so would welcome any help).
My thought was to see if I could get this to work by setting up receive post initialization and ignore the reload function until after I prove that the startup condition works.
from massive-js.
I had the name wrong -- try this.instance
(the actual instantiation of pg-promise) not this.pgp
.
from massive-js.
Awesome, that did it, thanks so much.
@dmfay: For my use case, this is probably all I need, as my DB is static and doesn't need to be reloaded during the lifetime of the node process. However, as I offered, I'll be willing to take a look at doing something that might be useful in the more general case if you think it would be worthwhile.
In case anyone else needs this, here's the change from the original problem example above. It's just a matter of setting the receive option after connecting (to avoid fouling up the introspection process), in the promise resolution, instead of in the driver settings. The magic bit is using db.instance.$config.options to access the driver settings.
Like so:
return massive(massiveConnSettings, {}, driverSettings).then(db => {
console.log('connected');
db.instance.$config.options.receive = (data, result, e) => {
camelizeColumns(data);
};
db.test.insert({ column_one: 1 });
db.test.find({}).then(resp => {
console.log('test rows: ', resp);
});
from massive-js.
I think it'd be useful! What you'd need to do is cache instance.$config.options.receive
in a variable at the beginning of the reload
function, delete it, and put it back at the end. For testing, look in test/connect.js; you can copy and paste the "returns a database connection" testcase and add the driver config with receive
to validate the new behavior. It should be fairly straightforward as these things go, but let me know if it gets confusing.
from massive-js.
OK, I'll take a look as soon as I can, and won't hesitate to ask for help :)
from massive-js.
@dmfay Feel free to say no if my experience level appears inadequate for this task. I'm pretty willing to roll up my sleeves, and go backfill areas I need more background on to proceed, but I probably need a little help getting started, and don't want to be a burden.
For what it's worth, I'd probably rate myself a good and diligent, but not greatly experienced JS developer. I do have a ton of RDBMS experience, including primarily PostgreSQL the last couple of years (but going back, believe it or not, to the early Ingres days, when I worked there as a support person), but mostly as a user, not a developer. And FWIW, I'm greatly interested in becoming a useful contributor to an OS project like this one.
Anyway, I've cloned the repo and wanted to start by running tests, but I'm struggling a little to get them to run properly. A first attempt yielded many failures :-( Is there any testing documentation? I presume I need to set up a DB with permissions and stuff, and could probably reverse engineer that by looking at a bunch of tests, but maybe there's a faster way?
Thanks in advance for any help, and willing to participate, or not, at whatever level makes sense.
from massive-js.
Oops. Just found https://github.com/dmfay/massive-js/blob/master/CONTRIBUTING.md
I'll start there :-)
from massive-js.
@dmfay OK, progress update.
I've added a few lines to the reload function in database.js:
at the top...
Database.prototype.reload = function() {
this.clean();
// cache pg-promise receive option config
const receiveOptionCached = this.instance.$config.options.receive;
delete this.instance.$config.options.receive;
and at the end...
// restore pg-promise receive option config
this.instance.$config.options.receive = receiveOptionCached
? receiveOptionCached
: null;
return this;
});
});
};
One issue and one question:
- Issue: the transactions > withTransaction > reloads and applies DDL: test fails with:
1) transactions
withTransaction
reloads and applies DDL:
TypeError: Cannot read property 'options' of undefined
at Database.reload (lib/database.js:66:72)
at db.withTransaction.co.wrap.mode.db.pgp.txMode.TransactionMode.tiLevel (test/database/with.js:164:23)
at db.withTransaction.co.wrap.mode.db.pgp.txMode.TransactionMode.tiLevel.next (<anonymous>)
at onFulfilled (node_modules/co/index.js:65:19)
at process.internalTickCallback (internal/process/next_tick.js:77:7)
All other tests pass, including a manual test passing in a receive: camelCase function (exactly like my original code at the top of this report - yay! :) ). I couldn't really figure out why this one failed.
- Should I save and restore an empty options.receive as null? undefined?
Once I get your feedback, I can build a test and send a PR.
Thanks for your assistance!
from massive-js.
- It failed because
this.instance.$config
was undefined when you tried to pulloptions.receive
off. I think that's a peculiarity of reloading within a transaction instead of the global context; just make sure$config
exists before you try to do anything with it. - I'd check whether
receiveOptionsCached
is truthy (if (!!receiveOptionsCached) ...
) before restoring; that way, if there wasn't anything there you don't need to worry about what to put back.
from massive-js.
Everything looks good, thank you! I've released v5.7.5.
If there's other stuff you're interested in tackling, feel free to have at it and I'll do my best to field questions :)
from massive-js.
Awesome. OK, this was my first OSS contribution. I'll keep an eye out for more.... I may get addicted :)
Thanks for supporting the effort.
from massive-js.
congrats! And beware, it's definitely habit-forming....
from massive-js.
Related Issues (20)
- Read replicas connections from Massive HOT 6
- Options fields does not work for insert HOT 4
- How do I add coordinate Document Tables creation with my migration tool? HOT 3
- Save to a table with column type jsonb[] HOT 16
- (node:533) UnhandledPromiseRejectionWarning: RangeError: Variable $1 out of range. Parameters array length: 0 HOT 3
- framework example for express.js HOT 10
- LIKE comparison on array using ANY() HOT 2
- Update body (jsonb) and field at once HOT 3
- Create type as enum HOT 2
- Issues with $ placeholds in QueryFiles, pg-promise HOT 6
- Better way to decompose using postgres HOT 1
- Transactions - getting error using async/await HOT 1
- Transaction that does insert and uses the id from that insert for next insert in transaction HOT 13
- Massive.js is not working with auto-increment fields HOT 4
- Document query generated includes >= operation HOT 2
- Problem successfully persisting or querying data, despite db.listTables() functioning correctly HOT 2
- Does not work with Oracle?? HOT 2
- Question: Named Parameter Syntax HOT 2
- Database.prototype.clone performance bottleneck HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from massive-js.