I'm really a newbie on DB programming and Next.js also.
I have tried the function that received json data should be INSERTed (MySQL) with prisma in Next.js API server.
According to the explanation of the prisma, the code for inserting new record was as follows.
const result = wait prisma.[db_name].create({data:[json_data_name]});
for the PUT data [json-data_name].
For every http PUT case , the db connection count was added and after about 500 times inserting, there broke out the problem of "Too many connections...".
I think that the number of record inserted is not confined to 500 or..,
I think the prisma function prisma.[db_name].create makes new connection.
How to insert 2000~3000 http PUT data into MySQL db with prisma for Next.js API server?
const prisma = new PrismaClient();
the code above was moved out of the API handler, then the problem was finished!.
for every call of API handler , new prisma was created and used.
it means a new connection to db was created.
Thank you.
Related
I have an application which needs to connect to and RDS (postgres) proxy with IAM. It makes use of the create_app method.
def create_app():
connex_app = connexion.App(__name__, specification_dir=base_apispec_dir)
connex_app.add_api("swagger.yaml", strict_validation=True)
app = connex_app.app
app.config.from_object(get_configuration())
ma.init_app(app)
db.init_app(app)
return connex_app
In this post there is an example of how to do this with SQLalchemy, but how do we connect with Flask-SQLAlchemy. In the example they use the #event.listen_for() event from SQLalchemy, but for that I need the engine, which I do not have.
It is possible to get it from the SQLalchemy object, but this gives to following error: No application found. Either work inside a view function or push.
Does anyone know how to make this connection working so the IAM-token can be refreshed every time it expires or just before that?
Hi i have problem with Presta WebService. I'm using prestashop with node (nestJS). I Created a connection with MySql database (Presta DB) with SSH tunelling. It works corectly, i can do any query, and SQL returns "OK statuses". I checked it by ssh client, (queries in temrinal) and data is updated in DB. Problem is when i want to select this data by PrestaWebService, when i pick data presta returns "old" propably cached data. On presta Admin i have ceching "off". After manually reset cache by admin panel button keep presta returns me 'old" data. Anyone know whats going on? :D
I found a problem. I used incorrect table. I queried ps_product but should ps_product_shop.
I have created my own PHP api for getting and deleting data from database but I want realtime change like firestore database.
So how can I listen for data changes in MySQL database? I know stream is the way but how to apply it in Flutter App.
Use a replication library and connect to the mysql server as a slave.
This will give you a feed of all database chagnes.
When i wanted to do a similar thing
i created a function that gets the data from database
then used a timer to call the function every 3 seconds.
After every three seconds the updated ui is rebuilt.
Dont forget to check if the page is mounted and also to dispose the timer
This is What i did
Timer timer = Timer.periodic(const Duration(seconds: 3), (timer) {
setState(() {
refreshProductQuantity();
});
});
I've recently started with pushing my locally tested Node,mongo, angularjs sites to live environments hosted on DigitalOcean.
I'm having inconsistency with ajax/http calls. on my Local machine, I am able to do http request and update an angularjs variable and this in return populates the html on the frontend. all works Great! now testing this on my server with same envireontment setup, the only time the variable load new data is when i refresh the page.
For example (not my actualy code):
Nodejs - app.js:
app.get('/getlist', requiredAuthentication, function(req, res) {
list.find({'username':req.session.user.username}, function(err,list) {
res.send(list);
});});
Angularjs - angular_app.js:
$scope.onClick = function (points, evt) {
$http.get('/getlist').then(function(response) {
$rootScope.list = response;});
};
Jade - home:
li(ng-repeat="row in list")
So like I said, this works perfectly on my local machine, but on my server I must refresh my page to load new data, it's as though my variable gets cached on the server.
Any idea would help.
Thanks.!
------- UPDATE - testing v0.1 --------
So after some intensive testing here is what I've found, but still no fix.
If I add new data via an http post, and I go look in my mongo db, I see the new data. Then when I click on the ng-click to retrieve the new data via HTTP, it doesn't return the new data, and is stuck on the old.
If I leave the page open for 10mins, and then click the button, it retrieves the new data, this is such a shlep.
Sounds like cache, but why des it work perfectly on my local?
When looking at the console > network > status. it is code 304, and this means nothing changed?
------- UPDATE - testing v0.2 --------
I've now tested the return data with a log in the console and I did the GET with ajax jQuery, and I'm getting the same issue/behaviour, it's stuck on the same collection of data, so my conclusion must be that node.js is causing the issues.
------- UPDATE - testing v0.3 --------
Okay so I've completely stopped mongo and switched everything to mysql using node-mysql. once again, on my local it works like a machine and on my actual server its laggy with reading new data.
I used Sequal PRO to access mysql and I started adding new entries to a table.
Opening my web url in the brower it Immediately showed the new entries. But after that, adding new entries or deleting entries only showed affect in 10mins or so.
So my conclusion is that Nodejs is caching like a mother, anyone know more bout this? am i really the only one every to experience this?
Try res.json for return data from node
app.get('/getlist', requiredAuthentication, function(req, res)
{
list.find({'username':req.session.user.username}, function(err,list)
{
res.json(list);
});
});
My conclusion to this issue was that port 80 was somehow caching the content of a page and will only load new data with a page refresh.
I upgrade Node and used latest Express. And I'm running my web app on a custom port, all is working now.
I have recently started development on a relatively simple WCF REST service which returns JSON formatted results. At first everything worked great, and the service was quickly up and running.
The main function of the service is to return a large chunk of data extracted from a database. This data rarely changes, so I decided to try and setup a caching mechanism to speed things up. To do this I planned to set InstanceContextMode.Single and ConcurrencyMode.Multiple, and then with some thread locks, safely return a static cached result. Every 5 minutes or so, or whenever IIS decides to clear everything, the data would be re-fetched from the database.
My issue is InstanceContextMode.Single does not behave as expected. My understanding is a single instance of my WCF service class should be created and maintained. However the behaviour I have is a completely new instance of my Class is created per call. This include re-initialising all static variables.
I tried changing the web service from webHttpBinding (used for REST) to wsHttpBinding and using the service as a SOAP config, but this results in exactly the same behaviour.
What am I doing wrong!!! Have spent way too long trying to figure this out.
Any help would be great!.
Strange, can you try this and tell me what happen then?
ServiceThrottlingBehavior ThrottleBehavior = new ServiceThrottlingBehavior();
ThrottleBehavior.MaxConcurrentSessions = 1;
ThrottleBehavior.MaxConcurrentCalls = 1;
ThrottleBehavior.MaxConcurrentInstances = 1;
ServiceHost Host = ...
Host.Description.Behaviors.Add(ThrottleBehavior);
And [how] do you know your single service instance isn't "Single"? You saw multiple database connection from profiler? Is that what suggested to you why your service isn't a single instance? From your service operation implementation, do you do some of the work on a separate thread?