Upgrade to Pro — share decks privately, control downloads, hide ads and more …

20170701 Eloquent 核心解構 讓 Laravel 支援更多資料庫

20170701 Eloquent 核心解構 讓 Laravel 支援更多資料庫

LaravelConf Taiwan 2017
講師:墨嗓 (陳佑竹)

主要涵蓋範圍,介紹 Eloquent 的結構,以及如何讓 Eloquent 支援更多的資料庫。

簡報錄影:https://goo.gl/VQ9gbJ

#Laravel #Eloquent #DBMaker #PHP

mouson(墨嗓)

July 01, 2017
Tweet

More Decks by mouson(墨嗓)

Other Decks in Technology

Transcript

  1. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Eloquent 核⼼心解構
    讓 Laravel ⽀支援更更多資料庫
    墨墨嗓 (陳佑⽵竹)

    2017-07-01

    LaravelConf Taiwan 2017

    View Slide

  2. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    墨墨嗓 (陳佑⽵竹)
    • @mouson
    • https://fb.me/mouson
    • https://github.com/mouson
    [email protected]
    • 世成科技 系統分析師
    • Laravel Taiwan、DevOps Taiwan
    志⼯工
    • Laravel 導入、系統規劃、分析、
    重構
    墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017

    View Slide

  3. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    三不會⼀一只有
    • 只有結構上的概念念介紹

    • 不會介紹有什什麼 Design Pattern

    • 不會做出⼀一個 Eloquent Driver

    • 不會 Live Coding

    View Slide

  4. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Motivation
    DBMaker
    DB
    Exec SQL
    Result
    Application
    Code

    View Slide

  5. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Motivation
    DBMaker
    DB
    Exec SQL
    Result
    Application
    Code
    source:
    https://zh.wikipedia.org/wiki/File:Spaghetti.jpg

    View Slide

  6. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Motivation
    DBMaker
    DB
    Exec SQL
    Result
    Application
    Code

    View Slide

  7. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Motivation
    DBMaker
    DB
    Exec SQL
    Result
    Application
    Code
    source:
    https://zh.wikipedia.org/wiki/File:Spaghetti.jpg
    https://zh.wikipedia.org/wiki/波动拳#/media/File:波动拳.gif

    View Slide

  8. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Motivation
    DBMaker
    DB
    Exec SQL
    Result
    Application
    Code
    source:
    https://zh.wikipedia.org/wiki/File:Spaghetti.jpg
    https://zh.wikipedia.org/wiki/波动拳#/media/File:波动拳.gif
    https://commons.wikimedia.org/w/index.php?curid=165211

    View Slide

  9. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Motivation
    DBMaker
    DB
    Exec SQL
    Result
    Application
    Code
    source:
    https://zh.wikipedia.org/wiki/File:Spaghetti.jpg
    https://zh.wikipedia.org/wiki/波动拳#/media/File:波动拳.gif
    https://commons.wikimedia.org/w/index.php?curid=165211

    View Slide

  10. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Debug

    View Slide

  11. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Debug Guy

    View Slide

  12. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    source: https://commons.wikimedia.org/wiki/File:豬八戒斬妖.jpg
    Debug Guy

    View Slide

  13. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Refactoring
    DBMaker
    Application
    Code
    DB
    Exec SQL
    Call
    Result Result
    Route Controller
    View
    Model

    View Slide

  14. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Refactoring
    DBMaker
    Laravel
    Application
    Code
    DB
    Exec SQL
    Call
    Result Result
    Route Controller
    View
    Model

    View Slide

  15. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Refactoring
    DBMaker
    Laravel
    Application
    Code
    DB
    Exec SQL
    Call
    Result Result
    Route Controller
    View
    Model
    ???
    ???

    View Slide

  16. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Source: https://www.youtube.com/watch?v=rClNZLXSKA8

    View Slide

  17. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Structure
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  18. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Structure
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    DBMaker

    View Slide

  19. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Connection
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Config/database.php

    View Slide

  20. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Connection
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Database
    ServiceProvider
    \Illuminate\Database
    Config/database.php

    View Slide

  21. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Connection
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Database
    ServiceProvider
    \Illuminate\Database
    DatabaseManager
    \Illuminate\Database
    Config/database.php

    View Slide

  22. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Connection
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Database
    ServiceProvider
    \Illuminate\Database
    DatabaseManager
    \Illuminate\Database
    ConnectionFactory
    \Illuminate\Database\Connectors
    Config/database.php

    View Slide

  23. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Connection
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Database
    ServiceProvider
    \Illuminate\Database
    DatabaseManager
    \Illuminate\Database
    ConnectionFactory
    \Illuminate\Database\Connectors
    Connection
    \Illuminate\Database
    Config/database.php

    View Slide

  24. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Connection
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Database
    ServiceProvider
    \Illuminate\Database
    DatabaseManager
    \Illuminate\Database
    ConnectionFactory
    \Illuminate\Database\Connectors
    Connection
    \Illuminate\Database
    Config/database.php

    View Slide

  25. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Connection
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Database
    ServiceProvider
    \Illuminate\Database
    DatabaseManager
    \Illuminate\Database
    ConnectionFactory
    \Illuminate\Database\Connectors
    Connection
    \Illuminate\Database
    Connector
    \Illuminate\Database\Connectors
    Config/database.php

    View Slide

  26. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Connection
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Database
    ServiceProvider
    \Illuminate\Database
    DatabaseManager
    \Illuminate\Database
    ConnectionFactory
    \Illuminate\Database\Connectors
    Connection
    \Illuminate\Database
    Connector
    \Illuminate\Database\Connectors
    Config/database.php

    View Slide

  27. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Connection
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Database
    ServiceProvider
    \Illuminate\Database
    DatabaseManager
    \Illuminate\Database
    ConnectionFactory
    \Illuminate\Database\Connectors
    Connection
    \Illuminate\Database
    Connector
    \Illuminate\Database\Connectors
    PDO
    \PDO
    Config/database.php

    View Slide

  28. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Connection
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Database
    ServiceProvider
    \Illuminate\Database
    DatabaseManager
    \Illuminate\Database
    ConnectionFactory
    \Illuminate\Database\Connectors
    Connection
    \Illuminate\Database
    Connector
    \Illuminate\Database\Connectors
    PDO
    \PDO
    Config/database.php MySQL
    SQLServe
    SQLite

    View Slide

  29. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Connection
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Database
    ServiceProvider
    \Illuminate\Database
    DatabaseManager
    \Illuminate\Database
    ConnectionFactory
    \Illuminate\Database\Connectors
    Connection
    \Illuminate\Database
    Connector
    \Illuminate\Database\Connectors
    PDO
    \PDO
    Config/database.php MySQL
    SQLServe
    SQLite

    View Slide

  30. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Connection
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Database
    ServiceProvider
    \Illuminate\Database
    DatabaseManager
    \Illuminate\Database
    ConnectionFactory
    \Illuminate\Database\Connectors
    Connection
    \Illuminate\Database
    Connector
    \Illuminate\Database\Connectors
    PDO
    \PDO
    Config/database.php MySQL
    SQLServe
    SQLite

    View Slide

  31. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    What is PDO ?

    View Slide

  32. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017 Source: http://php.net/manual/en/intro.pdo.php

    View Slide

  33. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    PDO provides a data-
    access abstraction
    MySQL
    SQLServer
    SQLite

    View Slide

  34. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    PDO provides a data-
    access abstraction
    MySQL
    SQLServer
    SQLite
    MySQL
    select `id`, `name`
    from `users`

    View Slide

  35. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    PDO provides a data-
    access abstraction
    MySQL
    SQLServer
    SQLite
    MySQL
    select `id`, `name`
    from `users`
    PHP Data Objects (PDO)
    $conn = new PDO(...)
    $conn->query($sql);
    ...

    View Slide

  36. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    PDO provides a data-
    access abstraction
    MySQL
    SQLServer
    SQLite
    MySQL
    select `id`, `name`
    from `users`
    MS SQLServer PHP Data Objects (PDO)
    $conn = new PDO(...)
    $conn->query($sql);
    ...

    View Slide

  37. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    PDO provides a data-
    access abstraction
    MySQL
    SQLServer
    SQLite
    MySQL
    select `id`, `name`
    from `users`
    MS SQLServer
    select [id], [name]
    from [users]
    PHP Data Objects (PDO)
    $conn = new PDO(...)
    $conn->query($sql);
    ...

    View Slide

  38. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    PDO provides a data-
    access abstraction
    MySQL
    SQLServer
    SQLite
    MySQL
    select `id`, `name`
    from `users`
    MS SQLServer
    select [id], [name]
    from [users]
    PHP Data Objects (PDO)
    $conn = new PDO(...)
    $conn->query($sql);
    ...

    View Slide

  39. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    PDO provides a data-
    access abstraction
    MySQL
    SQLServer
    SQLite
    MySQL
    select `id`, `name`
    from `users`
    MS SQLServer
    select [id], [name]
    from [users]
    SQLite
    PHP Data Objects (PDO)
    $conn = new PDO(...)
    $conn->query($sql);
    ...

    View Slide

  40. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    PDO provides a data-
    access abstraction
    MySQL
    SQLServer
    SQLite
    MySQL
    select `id`, `name`
    from `users`
    MS SQLServer
    select [id], [name]
    from [users]
    SQLite
    select "id", "name"
    from "users"
    PHP Data Objects (PDO)
    $conn = new PDO(...)
    $conn->query($sql);
    ...

    View Slide

  41. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL
    SQLServer
    SQLite
    MySQL
    select `id`, `name`
    from `users`
    MS SQLServer
    select [id], [name]
    from [users]
    SQLite
    select "id", "name"
    from "users"
    PHP Data Objects (PDO)
    $conn = new PDO(...)
    $conn->query($sql);
    ...
    "Standard" Query Lang ?

    View Slide

  42. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Connection
    Database
    ServiceProvider
    \Illuminate\Database
    DatabaseManager
    \Illuminate\Database
    ConnectionFactory
    \Illuminate\Database\Connectors
    Connection
    \Illuminate\Database
    Connector
    \Illuminate\Database\Connectors
    PDO
    \PDO
    Config/database.php MySQL
    SQLServe
    SQLite
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  43. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Connection
    Database
    ServiceProvider
    \Illuminate\Database
    DatabaseManager
    \Illuminate\Database
    ConnectionFactory
    \Illuminate\Database\Connectors
    Connection
    \Illuminate\Database
    Connector
    \Illuminate\Database\Connectors
    PDO
    \PDO
    Config/database.php MySQL
    SQLServe
    SQLite
    Builder
    \Illuminate\Database\Query
    \Illuminate\Database\Schema
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  44. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Connection
    Database
    ServiceProvider
    \Illuminate\Database
    DatabaseManager
    \Illuminate\Database
    ConnectionFactory
    \Illuminate\Database\Connectors
    Connection
    \Illuminate\Database
    Connector
    \Illuminate\Database\Connectors
    PDO
    \PDO
    Config/database.php MySQL
    SQLServe
    SQLite
    Builder
    \Illuminate\Database\Query
    \Illuminate\Database\Schema
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  45. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Builder
    MySQL
    SQLServer
    SQLite
    MySQL
    select `id`, `name`
    from `users`
    MS SQLServer
    select [id], [name]
    from [users]
    SQLite
    select "id", "name"
    from "users"
    PDO
    Builder

    View Slide

  46. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Builder
    MySQL
    SQLServer
    SQLite
    MySQL
    select `id`, `name`
    from `users`
    MS SQLServer
    select [id], [name]
    from [users]
    SQLite
    select "id", "name"
    from "users"
    PDO
    Builder
    DB::table('users')
    ->select('id','name')
    ->get();

    View Slide

  47. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Builder
    MySQL
    SQLServer
    SQLite
    MySQL
    select `id`, `name`
    from `users`
    MS SQLServer
    select [id], [name]
    from [users]
    SQLite
    select "id", "name"
    from "users"
    PDO
    Builder
    DB::table('users')
    ->select('id','name')
    ->get();
    DB::table('users')
    ->select('id','name')
    ->get();

    View Slide

  48. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Builder
    MySQL
    SQLServer
    SQLite
    MySQL
    select `id`, `name`
    from `users`
    MS SQLServer
    select [id], [name]
    from [users]
    SQLite
    select "id", "name"
    from "users"
    PDO
    Builder
    DB::table('users')
    ->select('id','name')
    ->get();

    View Slide

  49. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Connection
    Database
    ServiceProvider
    \Illuminate\Database
    DatabaseManager
    \Illuminate\Database
    ConnectionFactory
    \Illuminate\Database\Connectors
    Connection
    \Illuminate\Database
    Connector
    \Illuminate\Database\Connectors
    PDO
    \PDO
    Config/database.php MySQL
    SQLServe
    SQLite
    Builder
    \Illuminate\Database\Query
    \Illuminate\Database\Schema
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  50. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Laravel Connection
    Database
    ServiceProvider
    \Illuminate\Database
    DatabaseManager
    \Illuminate\Database
    ConnectionFactory
    \Illuminate\Database\Connectors
    Connection
    \Illuminate\Database
    Connector
    \Illuminate\Database\Connectors
    PDO
    \PDO
    Config/database.php MySQL
    SQLServe
    SQLite
    Builder
    \Illuminate\Database\Query
    \Illuminate\Database\Schema
    Grammar
    \Illuminate\Database

    View Slide

  51. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Migrations
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  52. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Migrations
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  53. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Build a Building
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  54. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Build a Building
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Blueprint

    View Slide

  55. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Build a Building
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Blueprint Builder

    View Slide

  56. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Build a Building
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Blueprint Builder Grammar

    View Slide

  57. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Build a Building
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Blueprint Builder Grammar
    Worker

    View Slide

  58. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Build a Building
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Blueprint Builder Grammar
    Building
    Worker

    View Slide

  59. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    class CreateUsersTable extends Migration
    {
    /**
    * Run the migrations.
    *
    * @return void
    */
    public function up()
    {
    Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
    });
    }
    /**
    * Reverse the migrations.
    *
    * @return void
    */
    public function down()
    {
    Schema::dropIfExists('users');
    }
    }
    Migrations
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  60. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    class CreateUsersTable extends Migration
    {
    /**
    * Run the migrations.
    *
    * @return void
    */
    public function up()
    {
    Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
    });
    }
    /**
    * Reverse the migrations.
    *
    * @return void
    */
    public function down()
    {
    Schema::dropIfExists('users');
    }
    }
    Schema
    Schema
    Schema
    Migration
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  61. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Migrations
    Schema
    Illuminate\Support\Facades
    MigrationServiceProvider

    DatabaseMigrationRepository

    Migrator

    MigrationCreator
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  62. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Migrations
    Schema
    Illuminate\Support\Facades
    public static function connection($name) {
    return static::$app['db']->connection($name)
    ->getSchemaBuilder();
    }
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  63. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Migrations
    Schema
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    DB
    public static function connection($name) {
    return static::$app['db']->connection($name)
    ->getSchemaBuilder();
    }
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  64. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Migrations
    Schema
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    DB
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  65. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    class CreateUsersTable extends Migration
    {
    /**
    * Run the migrations.
    *
    * @return void
    */
    public function up()
    {
    Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
    });
    }
    /**
    * Reverse the migrations.
    *
    * @return void
    */
    public function down()
    {
    Schema::dropIfExists('users');
    }
    }
    Blueprint
    Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
    });
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  66. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Migrations
    Schema
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    DB
    Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
    });

    View Slide

  67. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Migrations
    Schema
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    DB
    public function create($table, Closure $callback) {
    $this->build(tap(
    $this->createBlueprint($table),
    function ($blueprint) use ($callback) {
    $blueprint->create();
    $callback($blueprint);
    }));
    }
    Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
    });

    View Slide

  68. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Migrations
    Schema
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    DB
    Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
    });
    public function create($table, Closure $callback) {
    $this->build(tap(
    $this->createBlueprint($table),
    function ($blueprint) use ($callback) {
    $blueprint->create();
    $callback($blueprint);
    }));
    }

    View Slide

  69. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Migrations
    Schema
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    DB
    Blueprint
    Illuminate\Database\Schema
    Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
    });
    public function create($table, Closure $callback) {
    $this->build(tap(
    $this->createBlueprint($table),
    function ($blueprint) use ($callback) {
    $blueprint->create();
    $callback($blueprint);
    }));
    }

    View Slide

  70. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Migrations
    Schema
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    DB
    Blueprint
    Illuminate\Database\Schema
    Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
    });
    public function create($table, Closure $callback) {
    $this->build(tap(
    $this->createBlueprint($table),
    function ($blueprint) use ($callback) {
    $blueprint->create();
    $callback($blueprint);
    }));
    }

    View Slide

  71. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Migrations
    Schema
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    DB
    Blueprint
    Illuminate\Database\Schema
    Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
    });
    protected function build(Blueprint $blueprint)
    {
    $blueprint->build($this->connection, $this->grammar);
    }

    View Slide

  72. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Migrations
    Schema
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    DB
    Blueprint
    Illuminate\Database\Schema
    Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
    });
    protected function build(Blueprint $blueprint)
    {
    $blueprint->build($this->connection, $this->grammar);
    }
    Grammar
    Illuminate\Database\Schema\Grammars

    View Slide

  73. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Migrations
    Grammar
    Illuminate\Database\Schema\Grammars
    Schema
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Blueprint
    Illuminate\Database\Schema
    DB
    Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
    });
    public function build(Connection $connection, Grammar
    $grammar) {
    foreach ($this->toSql($connection, $grammar) as
    $statement) {
    $connection->statement($statement);
    }
    }

    View Slide

  74. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Migrations
    Grammar
    Illuminate\Database\Schema\Grammars
    Schema
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Blueprint
    Illuminate\Database\Schema
    DB
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  75. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Migrations
    Grammar
    Illuminate\Database\Schema\Grammars
    Schema
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Blueprint
    Illuminate\Database\Schema
    DB
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  76. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    QueryBuilder
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  77. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    DB::table('users')
    ->select('id', 'name')
    ->get();
    QueryBuilder
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  78. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    QueryBuilder
    Grammar
    Illuminate\Database\Schema\Grammars
    DB
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Processor
    Illuminate\Database\Schema\Processors
    DB
    DB::table('users')
    ->select('id', 'name')
    ->get();
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  79. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    QueryBuilder
    Grammar
    Illuminate\Database\Schema\Grammars
    DB
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Processor
    Illuminate\Database\Schema\Processors
    DB
    DB::table('users')
    ->select('id', 'name')
    ->get();
    public function table($table) {
    return $this->query()
    ->from($table);
    }

    View Slide

  80. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    QueryBuilder
    Grammar
    Illuminate\Database\Schema\Grammars
    DB
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Processor
    Illuminate\Database\Schema\Processors
    DB
    DB::table('users')
    ->select('id', 'name')
    ->get();
    public function table($table) {
    return $this->query()
    ->from($table);
    }

    View Slide

  81. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    QueryBuilder
    Grammar
    Illuminate\Database\Schema\Grammars
    DB
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Processor
    Illuminate\Database\Schema\Processors
    DB
    DB::table('users')
    ->select('id', 'name')
    ->get();
    public function query() {
    return new QueryBuilder(
    $this,
    $this->getQueryGrammar(),
    $this->getPostProcessor()
    );
    }

    View Slide

  82. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    QueryBuilder
    Grammar
    Illuminate\Database\Schema\Grammars
    DB
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Processor
    Illuminate\Database\Schema\Processors
    DB
    DB::table('users')
    ->select('id', 'name')
    ->get();
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    public function table($table) {
    return $this->query()
    ->from($table);
    }

    View Slide

  83. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    QueryBuilder
    Grammar
    Illuminate\Database\Schema\Grammars
    DB
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Processor
    Illuminate\Database\Schema\Processors
    DB
    public function select($columns = ['*']) {
    $this->columns = is_array($columns) ?
    $columns : func_get_args();
    return $this;
    }
    DB::table('users')
    ->select('id', 'name')
    ->get();

    View Slide

  84. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    QueryBuilder
    Grammar
    Illuminate\Database\Schema\Grammars
    DB
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Processor
    Illuminate\Database\Schema\Processors
    DB
    public function get($columns = ['*']) {
    $original = $this->columns;
    ...略略...
    $results = $this->processor
    ->processSelect(
    $this,
    $this->runSelect()
    );
    ...略略...
    DB::table('users')
    ->select('id', 'name')
    ->get();

    View Slide

  85. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    QueryBuilder
    Grammar
    Illuminate\Database\Schema\Grammars
    DB
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Processor
    Illuminate\Database\Schema\Processors
    DB
    DB::table('users')
    ->select('id', 'name')
    ->get();
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    public function get($columns = ['*']) {
    $original = $this->columns;
    ...略略...
    $results = $this->processor
    ->processSelect(
    $this,
    $this->runSelect()
    );
    ...略略...

    View Slide

  86. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    QueryBuilder
    Grammar
    Illuminate\Database\Schema\Grammars
    DB
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Processor
    Illuminate\Database\Schema\Processors
    DB
    protected function runSelect()
    {
    return $this->connection->select(
    $this->toSql(),
    $this->getBindings(),
    !$this->useWritePdo
    );
    }
    DB::table('users')
    ->select('id', 'name')
    ->get();

    View Slide

  87. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    QueryBuilder
    Grammar
    Illuminate\Database\Schema\Grammars
    DB
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Processor
    Illuminate\Database\Schema\Processors
    DB
    DB::table('users')
    ->select('id', 'name')
    ->get();
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    protected function runSelect()
    {
    return $this->connection->select(
    $this->toSql(),
    $this->getBindings(),
    !$this->useWritePdo
    );
    }

    View Slide

  88. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    QueryBuilder
    Grammar
    Illuminate\Database\Schema\Grammars
    DB
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Processor
    Illuminate\Database\Schema\Processors
    DB
    public function toSql()
    {
    return $this->grammar
    ->compileSelect($this);
    }
    DB::table('users')
    ->select('id', 'name')
    ->get();

    View Slide

  89. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    QueryBuilder
    Grammar
    Illuminate\Database\Schema\Grammars
    DB
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Processor
    Illuminate\Database\Schema\Processors
    DB
    DB::table('users')
    ->select('id', 'name')
    ->get();
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    protected function runSelect()
    {
    return $this->connection->select(
    $this->toSql(),
    $this->getBindings(),
    !$this->useWritePdo
    );
    }

    View Slide

  90. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    QueryBuilder
    Grammar
    Illuminate\Database\Schema\Grammars
    DB
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Processor
    Illuminate\Database\Schema\Processors
    DB
    DB::table('users')
    ->select('id', 'name')
    ->get();
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    public function get($columns = ['*']) {
    $original = $this->columns;
    ...略略...
    $results = $this->processor
    ->processSelect(
    $this,
    $this->runSelect()
    );
    ...略略...

    View Slide

  91. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    How To Create Own Driver ?
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    DBMaker
    ???
    ???

    View Slide

  92. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    PDO Support ?
    Source: http://php.net/manual/en/pdo.drivers.php

    View Slide

  93. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Connection
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Database
    ServiceProvider
    \Illuminate\Database
    DatabaseManager
    \Illuminate\Database
    ConnectionFactory
    \Illuminate\Database\Connectors
    Connection
    \Illuminate\Database
    Connector
    \Illuminate\Database\Connectors
    PDO
    \PDO
    Config/database.php MySQL
    SQLServe
    SQLite
    Builder
    \Illuminate\Database\Query
    \Illuminate\Database\Schema
    Grammar
    \Illuminate\Database

    View Slide

  94. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel Migrations
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations
    Grammar
    Illuminate\Database\Schema\Grammars
    Schema
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Blueprint
    Illuminate\Database\Schema
    DB

    View Slide

  95. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Laravel QueryBuilder
    Grammar
    Illuminate\Database\Schema\Grammars
    DB
    Illuminate\Support\Facades
    Connection
    Illuminate\Database
    Builder
    Illuminate\Database\Schema
    Processor
    Illuminate\Database\Schema\Processors
    DB
    MySQL
    SQLite
    PostgreSQL
    SQL Server
    Laravel Model
    Application
    Code
    DB
    Exec
    SQL
    Call
    Result
    Result
    Eloquent Model
    Query Builder
    DB
    Connection
    (PHP Data
    Objects)
    Migrations

    View Slide

  96. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017

    View Slide

  97. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips
    • Data Type - Numeric/Char/Time/JSON

    • Auto Increment Support ?

    • Start From Unit Test

    View Slide

  98. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips
    • Data Type - Numeric/Char/Time/JSON

    • Auto Increment Support ?

    • Start From Unit Test

    View Slide

  99. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips - Data Type - Integer

    View Slide

  100. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips - Data Type - Integer
    MySQL
    int

    4 byte
    bigint

    8 byte
    mediumint

    3 byte
    smallint

    2 byte
    tinyint

    1 byte

    View Slide

  101. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips - Data Type - Integer
    MySQL
    int

    4 byte
    bigint

    8 byte
    mediumint

    3 byte
    smallint

    2 byte
    tinyint

    1 byte
    SQLite
    integer
    integer
    integer
    integer
    integer

    View Slide

  102. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips - Data Type - Integer
    MySQL
    int

    4 byte
    bigint

    8 byte
    mediumint

    3 byte
    smallint

    2 byte
    tinyint

    1 byte
    SQLite
    integer
    integer
    integer
    integer
    integer
    SQLServer
    int

    4 byte
    bigint

    8 byte
    smallint

    2 byte
    tinyint

    1 byte

    View Slide

  103. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips - Data Type - Integer
    MySQL
    int

    4 byte
    bigint

    8 byte
    mediumint

    3 byte
    smallint

    2 byte
    tinyint

    1 byte
    SQLite
    integer
    integer
    integer
    integer
    integer
    SQLServer
    int

    4 byte
    bigint

    8 byte
    smallint

    2 byte
    tinyint

    1 byte
    Postgres
    integer

    4 byte
    bigint

    8 byte
    smallint

    2 byte

    View Slide

  104. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips - Data Type - Integer
    MySQL SQLite SQLServer Postgres
    int

    4 byte
    integer int

    4 byte
    integer

    4 byte
    bigint

    8 byte
    integer bigint

    8 byte
    bigint

    8 byte
    mediumint

    3 byte
    integer
    smallint

    2 byte
    integer smallint

    2 byte
    smallint

    2 byte
    tinyint

    1 byte
    integer tinyint

    1 byte
    protected function typeMediumInteger(Fluent $column)
    {
    return 'mediumint';
    }

    View Slide

  105. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips - Data Type - Integer
    MySQL SQLite SQLServer Postgres
    int

    4 byte
    integer int

    4 byte
    integer

    4 byte
    bigint

    8 byte
    integer bigint

    8 byte
    bigint

    8 byte
    mediumint

    3 byte
    integer
    smallint

    2 byte
    integer smallint

    2 byte
    smallint

    2 byte
    tinyint

    1 byte
    integer tinyint

    1 byte
    protected function typeMediumInteger(Fluent $column)
    {
    return 'integer';
    }

    View Slide

  106. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips - Data Type - Integer
    MySQL SQLite SQLServer Postgres
    int

    4 byte
    integer int

    4 byte
    integer

    4 byte
    bigint

    8 byte
    integer bigint

    8 byte
    bigint

    8 byte
    mediumint

    3 byte
    integer
    smallint

    2 byte
    integer smallint

    2 byte
    smallint

    2 byte
    tinyint

    1 byte
    integer tinyint

    1 byte

    View Slide

  107. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips - Data Type - Integer
    MySQL SQLite SQLServer Postgres
    int

    4 byte
    integer int

    4 byte
    integer

    4 byte
    bigint

    8 byte
    integer bigint

    8 byte
    bigint

    8 byte
    mediumint

    3 byte
    integer
    smallint

    2 byte
    integer smallint

    2 byte
    smallint

    2 byte
    tinyint

    1 byte
    integer tinyint

    1 byte
    protected function typeMediumInteger(Fluent $column)
    {
    return 'int';
    }

    View Slide

  108. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips
    • Data Type - Numeric/Char/Time/JSON

    • Auto Increment Support ?

    • Start From Unit Test

    View Slide

  109. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips - Auto Increment Support

    View Slide

  110. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips - Auto Increment Support
    MySQL
    auto_increment

    int
    auto_increment

    bigint
    auto_increment

    mediumint
    auto_increment

    smallint
    auto_increment

    tinyint

    View Slide

  111. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips - Auto Increment Support
    MySQL
    auto_increment

    int
    auto_increment

    bigint
    auto_increment

    mediumint
    auto_increment

    smallint
    auto_increment

    tinyint
    SQLite
    autoincrement

    integer
    autoincrement

    integer
    autoincrement

    integer
    autoincrement

    integer
    autoincrement

    integer

    View Slide

  112. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips - Auto Increment Support
    MySQL
    auto_increment

    int
    auto_increment

    bigint
    auto_increment

    mediumint
    auto_increment

    smallint
    auto_increment

    tinyint
    SQLite
    autoincrement

    integer
    autoincrement

    integer
    autoincrement

    integer
    autoincrement

    integer
    autoincrement

    integer
    SQLServer
    identity

    int
    identity

    bigint
    identity

    smallint
    identity

    tinyint

    View Slide

  113. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips - Auto Increment Support
    MySQL
    auto_increment

    int
    auto_increment

    bigint
    auto_increment

    mediumint
    auto_increment

    smallint
    auto_increment

    tinyint
    SQLite
    autoincrement

    integer
    autoincrement

    integer
    autoincrement

    integer
    autoincrement

    integer
    autoincrement

    integer
    SQLServer
    identity

    int
    identity

    bigint
    identity

    smallint
    identity

    tinyint
    Postgres
    serial

    4 byte
    bigserial

    8 byte
    smallserial

    2 byte

    View Slide

  114. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL SQLite SQLServer Postgres
    auto_increment

    int
    autoincrement

    integer
    identity

    int
    serial

    4 byte
    auto_increment

    bigint
    autoincrement

    integer
    identity

    bigint
    bigserial

    8 byte
    auto_increment

    mediumint
    autoincrement

    integer
    auto_increment

    smallint
    autoincrement

    integer
    identity

    smallint
    smallserial

    2 byte
    auto_increment

    tinyint
    autoincrement

    integer
    identity

    tinyint
    Tips - Auto Increment Support
    protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
    {
    if (in_array($column->type, $this->serials) && $column->autoIncrement) {
    return ' auto_increment primary key';
    }
    }

    View Slide

  115. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL SQLite SQLServer Postgres
    auto_increment

    int
    autoincrement

    integer
    identity

    int
    serial

    4 byte
    auto_increment

    bigint
    autoincrement

    integer
    identity

    bigint
    bigserial

    8 byte
    auto_increment

    mediumint
    autoincrement

    integer
    auto_increment

    smallint
    autoincrement

    integer
    identity

    smallint
    smallserial

    2 byte
    auto_increment

    tinyint
    autoincrement

    integer
    identity

    tinyint
    Tips - Auto Increment Support
    protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
    {
    if (in_array($column->type, $this->serials) && $column->autoIncrement) {
    return ' primary key autoincrement';
    }
    }

    View Slide

  116. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL SQLite SQLServer Postgres
    auto_increment

    int
    autoincrement

    integer
    identity

    int
    serial

    4 byte
    auto_increment

    bigint
    autoincrement

    integer
    identity

    bigint
    bigserial

    8 byte
    auto_increment

    mediumint
    autoincrement

    integer
    auto_increment

    smallint
    autoincrement

    integer
    identity

    smallint
    smallserial

    2 byte
    auto_increment

    tinyint
    autoincrement

    integer
    identity

    tinyint
    Tips - Auto Increment Support
    protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
    {
    if (in_array($column->type, $this->serials) && $column->autoIncrement) {
    return ' identity primary key';
    }
    }

    View Slide

  117. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL SQLite SQLServer Postgres
    auto_increment

    int
    autoincrement

    integer
    identity

    int
    serial

    4 byte
    auto_increment

    bigint
    autoincrement

    integer
    identity

    bigint
    bigserial

    8 byte
    auto_increment

    mediumint
    autoincrement

    integer
    auto_increment

    smallint
    autoincrement

    integer
    identity

    smallint
    smallserial

    2 byte
    auto_increment

    tinyint
    autoincrement

    integer
    identity

    tinyint
    Tips - Auto Increment Support

    View Slide

  118. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL SQLite SQLServer Postgres
    auto_increment

    int
    autoincrement

    integer
    identity

    int
    serial

    4 byte
    auto_increment

    bigint
    autoincrement

    integer
    identity

    bigint
    bigserial

    8 byte
    auto_increment

    mediumint
    autoincrement

    integer
    auto_increment

    smallint
    autoincrement

    integer
    identity

    smallint
    smallserial

    2 byte
    auto_increment

    tinyint
    autoincrement

    integer
    identity

    tinyint
    Tips - Auto Increment Support
    protected function typeMediumInteger(Fluent $column)
    {
    return $column->autoIncrement ? 'serial' : 'integer';
    }

    View Slide

  119. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    MySQL SQLite SQLServer Postgres
    auto_increment

    int
    autoincrement

    integer
    identity

    int
    serial

    4 byte
    auto_increment

    bigint
    autoincrement

    integer
    identity

    bigint
    bigserial

    8 byte
    auto_increment

    mediumint
    autoincrement

    integer
    auto_increment

    smallint
    autoincrement

    integer
    identity

    smallint
    smallserial

    2 byte
    auto_increment

    tinyint
    autoincrement

    integer
    identity

    tinyint
    Tips - Auto Increment Support
    protected function typeMediumInteger(Fluent $column)
    {
    return $column->autoIncrement ? 'serial' : 'integer';
    }
    protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
    {
    if (in_array($column->type, $this->serials) && $column->autoIncrement) {
    return ' primary key';
    }
    }

    View Slide

  120. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Tips
    • Data Type - Numeric/Char/Time/JSON

    • Auto Increment Support ?

    • Start From Unit Test

    View Slide

  121. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Start from UnitTest
    https://github.com/whatthejeff/nyancat-phpunit-resultprinter

    View Slide

  122. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Start from UnitTest
    https://github.com/whatthejeff/nyancat-phpunit-resultprinter

    View Slide

  123. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Start from UnitTest
    https://github.com/whatthejeff/nyancat-phpunit-resultprinter

    View Slide

  124. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Summary
    • PDO Support ?

    • DataType

    • Grammar

    • Start from unit test

    View Slide

  125. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    WE WANT YOU !!
    •PHP 後端⼯工程師
    •前端⼯工程師

    View Slide

  126. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017

    View Slide

  127. 墨墨嗓 (陳佑⽵竹) / 2017.07.01
    LaravelConf Taiwan 2017
    Q&A

    View Slide