Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL specified by Sql annotation/attribute #29

Closed
koriym opened this issue Mar 8, 2022 · 6 comments · Fixed by #30
Closed

SQL specified by Sql annotation/attribute #29

koriym opened this issue Mar 8, 2022 · 6 comments · Fixed by #30
Labels
enhancement New feature or request

Comments

@koriym
Copy link
Member

koriym commented Mar 8, 2022

  • インジェクションされる変数名と同じプロパティ名の@SqlがSQL文の特定に使われます。
  • callableの代わりにInvokeInterfaceインターフェイスを使います。

PHP 7.x

class TodoRepository
{
    /**
     * @Sql("todo_insert")
     */
    public $todoCreate;

    /**
     * @Sql("todo_item_by_id")
     */
    public $todoItem;

    /**
     * @Sql("todo_list")
     */
    public $todoList;

    public function __construct(
        InvokeInterface $todoCreate,
        RowInterface $todoItem,
        RowListInterface $todoList
    ){
        $this->todoCreate = $todoCreate;
        $this->todoItem = $todoItem;
        $this->todoList = $todoList;
    }
}

$todoCreateにはtodo_insert.sqlSQL実行オブジェクトがインジェクトされます。

PHP8.x

<?php

declare(strict_types=1);

namespace Ray\Query;

use Ray\Query\Annotation\Sql;

class TodoRepository
{
    public function __construct(
        #[Sql('todo_insert')] public readonly InvokeInterface $todoCreate,
        #[Sql('todo_item_by_id')]  public readonly RowInterface $todoItem,
        #[Sql('todo_list')]  public readonly RowListInterface $todoList
    ){}
}

現状の@Namedの煩雑さと開発時の実行速度を改善します。

@koriym koriym added the enhancement New feature or request label Mar 8, 2022
koriym added a commit that referenced this issue Mar 8, 2022
koriym added a commit that referenced this issue Mar 8, 2022
@koriym koriym changed the title SqlアノテーションによるSQL指定 SQL specified by Sql annotation/attribute #29 Mar 8, 2022
@koriym koriym changed the title SQL specified by Sql annotation/attribute #29 SQL specified by Sql annotation/attribute Mar 8, 2022
@jingu
Copy link

jingu commented Mar 9, 2022

わかりやすく開発環境の速度向上も👍です。

@yuki777
Copy link

yuki777 commented Mar 28, 2022

todo_insert.sqlを指定するのであれば、
@Sql("todo_insert.sql") や、
@Sql("path/to/todo_insert.sql") などはどうでしょうか?

@koriym
Copy link
Member Author

koriym commented Mar 28, 2022

拡張子をつけていない(=ファイル指定ではなくIDの指定にしているのは)
sql以外のものに差し替える事ができることと、他のライブラリの整合性もあります。

@koriym
Copy link
Member Author

koriym commented Mar 28, 2022

そういう意味では@Sql@QueryIdにするのがいいのでしょうか?

@koriym
Copy link
Member Author

koriym commented Mar 31, 2022

ping @jingu @yuki777

@koriym
Copy link
Member Author

koriym commented Jun 8, 2024

Gentle reminder @jingu @yuki777

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants