Skip to content

Working examples of various technologies and practices - Docker, PHP8, JSON API, Vue3 + Typescript, Laravel8

License

Notifications You must be signed in to change notification settings

Janis-Rullis-IT/lara8-vue3-api

Repository files navigation

code-ruu

Working examples of various technologies and practices - Docker, JSON API, Vue2, laravel8, Phoenix/Elixir, Webpack.

Setup

Docker

.env

  • Copy the .env.example to .env.
  • Open .env and fill values in FILL_THIS.

setup.sh

./setup.sh

Add these to Your hosts file

172.60.2.10     ruu.local
172.60.2.11     api.ruu.local
172.60.2.14     pma.ruu.local

Open

FAQ

Why wasn't used a specific framework method?

Easier to migrate the project

By using less framework specific methods and more language-wide features makes a migration to other language, framework or version, less complex.

Why migrations are made using raw SQLs and not framework tools?

like schemor builders, seeders, ORM, or self-defined logic inside a Model.

Guaranteed result - What You See Is What Will Be Imported

Less space for side-effects.

Easier to migrate the project

if the project is moved to other language, framework or version.

What's wrong with using ORM or self defined PHP methods?

The choise to use RAW queries comes from a harsh experience.

Refactoring

Once worked in a project where migrations were written in the regular way - using ORM and methods defined in database models. Problems arise after a long code refactoring. Migration didn't work because the logic in the code has changed!

Migration to a different language

The migrations needs to be made incrementaly - step by step. It is easier to copy RAW queries in specific steps, than trying to convert the code to the specific SQL.

In raw queries it will happen as defined and the refactor migrations will incrementaly updated databases.

Why table names are called in a singular and not plural manner?

Up to you. Just be consistent though.

References

Personal reason

  • This approach comes from a project where an object files, classes, tables needed to be generated from a variable. It is easier to handle a singular word than plural. Example, man -> mans (incorrect but works), men on the other hand is harder to convert to singular without adding a new value.
  • Mostly table names are shorter. Good when have a lot of relation tables.

Why in some Model methods there is used a raw query?

Use case #1 Product::updatePrice(int $productId) - faster and more reliable

public static function updatePrice(int $productId)
	{
		return \DB::statement("
			UPDATE `product`
			SET `price` = (SELECT SUM(price) FROM ingredient WHERE `product_id` = ? AND deleted_at IS NULL)
			WHERE `id` = ?
        ", [$productId, $productId]);
	}

This query's execution is way faster and stable when called in SQL rather than in PHP (collect items, calculate and set).

Use case #2 updateSeq(int $productId) - faster and more reliable

	public static function updateSeq(int $productId)
	{
		return \DB::statement("
			UPDATE `ingredient`
			SET `seq` = (@i := @i+1)
			WHERE `product_id` = ?
			AND `deleted_at` IS NULL
			ORDER BY `seq` ASC
			(SELECT @i := 1)
        ", [$productId]);
	}

This query's execution is way faster and stable when called in SQL rather than in PHP (collect items, calculate and set).

Use case #2 - not in this project - limitations, control and easier to maintain

Sometimes the abstraction just can't exactly implement the desired outcome which could lead to silly workarounds and make the code less maintainable.

About

Working examples of various technologies and practices - Docker, PHP8, JSON API, Vue3 + Typescript, Laravel8

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published