node-sqlagent icon indicating copy to clipboard operation
node-sqlagent copied to clipboard

cant disable cache

Open driff opened this issue 8 years ago • 5 comments

hi, i'm having some problems using sqlagent with pg in a koa project, it all works great but the queries are getting cached and i don't want them to, is there a way i can disable the caching?

driff avatar Apr 25 '18 04:04 driff

Hi @driff, what cache do you mean? The module caches info about connection string and some meta info for sorting.

Thank you!

petersirka avatar Apr 25 '18 06:04 petersirka

hi @petersirka, i'm having the following problem, whenever i do a query, that data is cached for some reason, when i change the value of the data and call the same query, sqlagent brings me the cached query instead of the data in the DB, could it be because with koa i'm using the same instance of sqlagent everywhere?

for example:

ctx.sql.select('user', 'user_table').make(b=>{
      b.where('id', id);
      b.limit(1);
      b.fields('id', 'password', 'full_name', 'email')
  });
ctx.sql.exec((err, r)=>{
  resolve(r.user);
});

now say the password changed, when i call that query again it brings me the old password because it's cached.

driff avatar Apr 25 '18 15:04 driff

Hi @driff You should use it like this:

var Agent = require('sqlagent/pg').connect('connetion-string-to-postgresql');
app.context.Agent = Agent;

Then in the route handler:

var sql = ctx.Agent(); // this returns new instance of the Agent
sql.select('user', 'user_table').make...
sql.exec((err, r)=>{ ...

molda avatar Apr 25 '18 17:04 molda

@driff try to use @molda solution, the module has had a bad info in readme.

petersirka avatar Apr 25 '18 18:04 petersirka

Thanks!! it is working now!

driff avatar Apr 25 '18 20:04 driff