How to create stored procedures on sequelize - mysql

I started to learn sequelize with nodejs and I already maked a simple crud and start a new table on my database, but I do not have no clue about stored procedures with sequelize.
I did not find anything on the documentation...
It is possible to creat stored procedures with sequelize?
if so, how?
PS: I am using mysql 5.7.23

You just create them and use them using regular queries. There's no specific wrapper for them since Sequelize is an abstraction layer around different databases, each of which has its own method for defining and executing stored procedures.
In Sequelize it's pretty easy to run raw queries and define these:
sequelize.query("DEFINE ...");

Related

Laravel, what's the best practice to define Raw queries?

I'm crafting a Laravel App that will perform data synchronization from DB to DB. Using MySQL.
I have set up a set of SQL raw statements that will perform some data extraction across tables and using MySQL functions.
I don't have then a 1:1 relationship in order to relate Model to table (Common Eloquent approach)
What's the suggested approach to have things set up in a clean manner?
Store SQL statements as strings in a config file?
Issue virtual model Classes having the raw query inside as class constant?
Any best practice approach in Laravel flavour?

MySQL: Stored procedures

We are at the beginning to build up our site. Maybe you should check it out first to understand our problem: www.erasmusinn.com
Basically we are thinking about to use MySQL for stored procedures or not.
We only need to insert and update our database. Since we are planning to have thousands of database entities, it is very important that we use the most efficient way to update our database.
What do you think? Should we use MySQL?
Personally i would recommend PostgreSQL. It's free to use and easy to migrate from MySQL, and you can build your own functions, views, and have data relations.

Mysql Stored Procedure use

We have a large database and we do manipulations on it ever day by using the basic mysql queries.
Can anyone please tell me, what is the use of Mysql Stored Procedures?
The real use of the Stored Procedures comes into picture when have any application accessing database.
For example: Imagine that you have written all your database operations in the form of queries in your data access code.
Suppose, that you need to make any change to query , then you need to rebuild and redeploy the entire application in order see your changes.
But, if you are using stored procs and refering them in application, you can just make changes in your database with out need for redeploying the application.
So, obviously better security , maintainability and much more
Note: This is one scenario where stored procs are better than normal queries.
Usage of Stored Procs also avoids SQL Injection Attacks
In very simple words, stored procedures allow you to store your quires along with database, you can combine multiple quires in single procedure. now whenever you want to execute those quires just "CALL yourProcedure;"
Need to perform specific query daily ?
Read about MySQL events = stored procedures with scheduling capability !
https://dev.mysql.com/doc/refman/5.1/en/events.html

Accessing stored procedures with robconery / massive?

Another great article by Rob on the Massive ORM. What I haven't been able to find is references on how to access stored procedures. SubSonic had some issues with the overhead of using ActiveRecords, so I preferred to do data access with stored procedures, still using the SubSonic ORM.
What I haven't yet seen is outright support for things like SQL Server's TVP's in an ORM, so I modified SubSonic (shameless plug) to support them.
Is it possible to access SQL Server sprocs with Massive. Secondly, is there TVP support?
Stored procedures are not specially supported, but because you can execute basically any SQL with Massive they will just work:
Sample from the Massive Update 2 article:
var orders = tbl.Query("CustOrdersOrders #0", "ALFKI");
foreach (var item in orders) {
Console.WriteLine(item.OrderID);
}
And if your main focus is on stored procedures there is even a Micro ORM comparison article about it: MicroORMs for .NET: Stored Procedures

Hibernate and MySQL, Importing stored procedure

What's the proper way of importing/declaring stored procedure in Hibernate.
Currently,in my setup, Hibernate is configured to generate the schema if it doesn't exists, and I have import.sql file to insert referential data.
Should I include the source of the procedure into the import.sql file, or there's a better way to do so ?
It is not a good practice to use the hibernate to generate the table. There should be separate scripts created for that. Basically hbm2ddl.auto=create setting in hibernate is a temporary way to create the tables, but you should not be using it in a standard application. It is even unsafe to have this entry in your configuration settings.Read here for more.
If you have a import.sql that can generate the shcema and the other DB entities run it independent of the application. It is always best, not to mix up creating the DB entities (including stored procedures and tables) and using them.
There is none. Stored procedures are out of scope of hibernate. At most you can issue native SQL query , but it will bypass everything. Usually you just take sql script generated by schema export and enhance it manually