Do You Use SQL or ORM For Database Queries?
-
sebflo
- Verified Member

- Posts: 138
- Joined: October 9th, 2018, 1:16 pm
Do You Use SQL or ORM For Database Queries?
I have used both but gravitate to SQL instead of ORM.
I don't think there are performance benefits to ORM but its does look a lot cleaner in code when not using SQL stored procedures.
What do you use for your applications?
I generally just use SQL in code, and use stored procedures in code for the very heavy queries. A lot of my queries are now handled by LAMBDA functions and simply return JSON from an endpoint with all the joins being done as a stored procedure.
I don't think there are performance benefits to ORM but its does look a lot cleaner in code when not using SQL stored procedures.
What do you use for your applications?
I generally just use SQL in code, and use stored procedures in code for the very heavy queries. A lot of my queries are now handled by LAMBDA functions and simply return JSON from an endpoint with all the joins being done as a stored procedure.
- T.B.W
- Verified Member

- Posts: 1152
- Joined: March 26th, 2018, 1:34 pm
-
sebflo
- Verified Member

- Posts: 138
- Joined: October 9th, 2018, 1:16 pm
ORM (Object-relational mapping) is essentially a different way of accessing data from a database in OOP languages, can be used with or without frameworks but are very popular with web frameworks such as Laravel and Codeigniter.
Here is a php example using SQL in code, and an example using php with ORM in code.
ORM
Code: Select all
//Gets list of titles, and names from roles table
$roles = DB::table('roles')->pluck('title', 'name');
//Returns data from database
return $roles;
Code: Select all
//Gets list of titles, and names from roles table
$roles = $db->prepare("SELECT roles.title, roles.name FROM roles" );
//Executes query
$roles->execute();
//Fetch Data As Array
$roles = $roles->fetchAll(PDO::FETCH_ASSOC);
//Returns data from database
return $roles;
Code: Select all
//Gets list of titles, and names from roles table
$roles = $db->prepare("CALL: get_names_and_tables(?)" );
//Executes query
$roles->execute(array(null));
//Fetch Data As Array
$roles = $roles->fetchAll(PDO::FETCH_ASSOC);
//Returns data from database
return $roles;
- LuKenGas
- Verified Member

- Posts: 2209
- Joined: February 23rd, 2018, 8:07 am
-
sebflo
- Verified Member

- Posts: 138
- Joined: October 9th, 2018, 1:16 pm
- bestfreeporn
- Verified Member

- Posts: 2308
- Joined: February 20th, 2018, 6:34 pm
- Referrals: 1
- koster
- Verified Member

- Posts: 954
- Joined: June 25th, 2018, 4:42 am
- Contact:
I am a sql guy and not had a chance to try anything else for databases. But I am open to ideas.
-
sebflo
- Verified Member

- Posts: 138
- Joined: October 9th, 2018, 1:16 pm
For workflow speed, I think ORM is faster when it comes to most workflows.
However for performance, stored procedures will be faster (not going to notice until system is under heavy load).
-
CTE
- Verified Member

- Posts: 611
- Joined: March 13th, 2018, 3:31 pm
Mysql is here to stay as long as WordPress uses it.
My 1 peso
My 1 peso
-
sebflo
- Verified Member

- Posts: 138
- Joined: October 9th, 2018, 1:16 pm
SQL is definitely here to stay, Wordpress for the most part uses MySQL but you can technically use any SQL engine out there, Maria DB, Amazon Aurora, Postgresql.
NoSQL databases started to make some noise but with MySQL 8 adding json data types I think they killed the game.
ORM just makes SQL syntax a lot cleaner regardless of what SQL database you are using (MySQL, Postgresql, MsSQL, Etc). Personally I use a lot of stored procedures instead of ORM but I do thing ORM makes code look a lot cleaner.
The only issue I have faced with MySQL is it's indexing system is a bit slow for very heavy database applications (500+ Million Records with multiple tables). Even with foreign keys and all the optimization standards, it can get laggy. Of course there is always a solution and there are plenty of solutions for SQL indexing and searching, I have been a fan of http://sphinxsearch.com however there are plenty of other options out there.
Here is a popular SQL, ORM Framework: https://www.doctrine-project.org
- pussyhunter
- Verified Member

- Posts: 959
- Joined: July 13th, 2018, 3:40 am
SQL not tried ORM and see no reason to stop using SQL, it works just fine and dandy and is fast.
-
monsta
- Verified Member

- Posts: 1459
- Joined: March 21st, 2018, 3:37 pm
- britporn_mike
- Verified Member

- Posts: 1134
- Joined: May 3rd, 2018, 2:43 pm
Less code = good news to my ears, means faster page load speeds.
- killah
- Verified Member

- Posts: 1225
- Joined: March 7th, 2018, 6:18 pm
So what are the main advantages of using ORM over SQL
-
born2bewild
- Verified Member

- Posts: 1655
- Joined: May 22nd, 2018, 6:47 pm
- Title: work hard play hard