技術情報

Laravel Livewire

I am talking about the brief introduction about laravel livewire today.

Its aim is to provide a modern and dynamic web experience without having to waste time with reactive web frameworks or Javascript at all.
And for the most part: it can. Livewire really works, and in the next few years we will almost definitely see some big, serious projects on it.

When you activate the livewire, you will

– Write a PHP class, which will act as the backend part of a frontend component. Public fields will be visible to Livewire.

– Write an interface component in the Laravel (Blade) template language. This component refers to the fields in the backend component that you wrote earlier.

– Write methods in your backend component class that change the state of public fields.

– Create an instance of the component in another view or another component.

– When you visit the page, Livewire will render the initial state of the component as HTML and inject it into the page you see. Livewire will have already attached auto-generated JavaScript events to the page, which call the methods you wrote in step 3 above.

– When you take action, the Javascript events that Livewire generates will make an AJAX request to the Livewire endpoint on the backend. This will call the method you wrote, changing the public properties you defined.

-Your backend component’s render method is then called, which produces a snippet of HTML. This HTML snippet is the response to the AJAX request.

– Finally, the client-side Livewire component hot-patches this HTML on the page.

Further more you can look up the livewire lifecycle hooks more details here.

https://laravel-livewire.com/docs/2.x/lifecycle-hooks

Livewire has lots of interesting features but it still have some drawbacks as follow.

– Livewire violates the separation of concerns

– Livewire violates the single-responsibility principle

– Livewire complicates the development workflow

– Too Many AJAX Requests

– Livewire is difficult to test

And Finally maintainability would be harder as the application grows.



InnoDB vs MyISAM

I talked about what is the MySQL storage engine last week. Today I will talk about the main difference between InnoDB and MyISAM.

The main difference between MyISAM and InnoDB are :

MyISAM does not support transactions by tables while InnoDB supports.

There are no possibility of row-level locking, relational integrity in MyISAM but with InnoDB this is possible. MyISAM has table-level locking.

InnoDB does not support FULLTEXT index while MyISAM supports.

Performance speed of MyISAM table is much higher as compared with tables in InnoDB.

InnoDB is better option while you are dealing with larger database because it supports transactions, volume while MyISAM is suitable for small project.

As InnoDB supports row-level locking which means inserting and updating is much faster as compared with MyISAM.

InnoDB supports ACID (Atomicity, Consistency, Isolation and Durability) property while MyISAM does not support.

In InnoDB table,AUTO_INCREMENT field is a part of index.

Once table in InnoDB is deleted then it can not re-establish.

InnoDB does not save data as table level so while implementation of select count(*) from table will again scan the whole table to calculate the number of rows while MyISAM save data as table level so you can easily read out the saved row number.

MyISAM does not support FOREIGN-KEY referential-integrity constraints while InnoDB supports.

By Yuuma



MySQL Storage Engines

Lets talk about the MySQL storage engines today.

A storage engine is a software module that uses a database management system to create, read, and update data in a database. There are two types of storage engines in MySQL: transactional and non-transactional.

For MySQL 5.5 and later, the default storage engine is InnoDB. The default storage engine for MySQL prior to version 5.5 was MyISAM. Choosing the right storage engine is an important strategic decision that will affect future development. In this tutorial, we will use MyISAM, InnoDB, Memory, and CSV storage engines. If you are new to MySQL and are studying the MySQL database management system, then this is not a big concern. If you are planning a production database, things get more complicated.

MySQL supported storage engines:

  • InnoDB
  • MyISAM
  • Memory
  • CSV
  • Merge
  • Archive
  • etc.

Today I will talk about the two main engines of MySQL. InnoDB & MyISAM.

InnoDB

InnoDB tables are fully transaction and ACID compliant. They are also optimal for performance. The InnoDB table supports foreign key, commit, rollback, and forward operations. The size of an InnoDB table can be up to 64TB.

Like MyISAM, InnoDB tables are portable between different platforms and operating systems. MySQL also checks and repairs InnoDB tables, if necessary, at startup.

MyISAM

MyISAM extends the old ISAM storage engine. MyISAM tables are optimized for compression and speed. MyISAM tables are also portable across platforms and operating systems.

The size of the MyISAM table can be up to 256TB, which is huge. Also, MyISAM tables can be compressed into read-only tables to save space. At startup, MySQL checks MyISAM tables for corruption and even repairs them in case of errors. MyISAM tables are not transaction safe.

Before MySQL version 5.5, MyISAM was the default storage engine when you create a table without specifying the storage engine explicitly. Since version 5.5, MySQL uses InnoDB as the default storage engine.

By Yuuma



[Laravel] Passportを使用したBearer token認証[1]

PHPのLaravelフレームワークのPassportを使用したBearer token認証の方法について紹介いたします。今回はPassport実装テスト用のプロジェクトを準備するところまでを説明します。

続きを読む

Singleton Design Pattern

Singleton is one of the creational design pattern that allows you to ensure that a class has only one instance, while providing a global access point to this instance.

Make the single instance object class responsible for creation, initialization, access, and execution. Declare the instance as a member of private static data. Provides a public static member function that encapsulates all initialization code and provides access to the instance.

The client calls the access function (using the class name and the scope resolution operator) whenever a reference to the single instance is required.

The singleton should be considered only if the following three criteria are met:

Single instance ownership cannot reasonably be assigned
Lazy initialization is desirable
Global access is not provided otherwise

Lets take a look at code samples

PHP code sample

<?php

/**
 * Singleton class
 */
class LogSingleton {
    /**
     * I kept this attribute and constructor as private so that other sub class can't instantiate
     * it can also be protected if you want to allow sub classes to be instantiated
     */
    private static $intance = null;

    private function __construct() {
    }

    /**
     * I will assign the singleton instance if $instance is null.
     * otherwise will return directly.
     */
    public static function log() {
      if (self::$intance == null) {
         self::$intance = new LogSingleton();
      }
      return self::$intance;
    }

    //can also declare other public functions below.
    public function debugLog()
    {
      return "debug log";
    }
  }

//client code
$client = LogSingleton::log(); // this is the singleton instance.
var_dump($client->debugLog());

C# sample code

using System;

namespace HelloWorld
{
    class LogSingleton
    {
        /**
         * I kept this attributes as private so that other sub class can't instantiate
         * it can also be protected if you want to allow sub classes to be instantiated
         */
        private static LogSingleton instance;

        /**
         * for the first use for this class, s_lock will have a object.
         * This will later use along with lock function to protect from multi thread base.
         */
        private static readonly object s_lock = new object();

        public static LogSingleton log()
        {
            if (instance == null)
            {
                /**
                 * The client who has s_lock will proceed this condition.
                 */
                lock (s_lock)
                {
                    /**
                     * I will assign the singleton instance if instance is null.
                     * otherwise will return directly.
                     */
                    if (instance == null)
                    {
                        instance = new LogSingleton();
                    }
                }
            }
            return instance;
        }

        //can also declare other public functions below.
        public string debugLog()
        {
            return "debug log";
        }

        //client code
        class Program
        {
            static void Main(string[] args)
            {
                var client = LogSingleton.log(); // this is the singleton instance.
                Console.WriteLine(client.debugLog());

            }
        }
    }

}

By Yuuma




アプリ関連ニュース

お問い合わせはこちら

お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

tel. 06-6454-8833(平日 10:00~17:00)

お問い合わせフォーム