micayael / native-query-from-file-builder-bundle
用于从yaml文件执行原生查询的Bundle
2.0.6
2023-06-09 15:39 UTC
Requires
- php: ^7.2|^8.0
- adbario/php-dot-notation: ^2.0
- doctrine/doctrine-bundle: ^2.5
- doctrine/orm: ^2.5 || ^2.6
- symfony/config: ^5.4|^6.0
- symfony/dependency-injection: ^5.4|^6.0
- symfony/filesystem: ^5.4|^6.0
- symfony/http-kernel: ^5.4|^6.0
- symfony/yaml: ^5.4|^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.3
- phpmd/phpmd: @stable
- phpstan/phpstan: ^1.4
- symfony/framework-bundle: ^5.4|^6.0
- symfony/test-pack: ^1.0
- symfony/var-dumper: ^5.4|^6.0
README
此Bundle允许您将SQL SELECT语句写入yaml文件以实现更好的组织,然后在应用程序中执行它们
安装
使用Symfony Flex的应用程序
打开命令行,进入您的项目目录并执行
- Symfony <5.4
$ composer require micayael/native-query-from-file-builder-bundle
- Symfony >=5.4
$ composer require micayael/native-query-from-file-builder-bundle:~2.0
不使用Symfony Flex的应用程序
步骤1:下载Bundle
打开命令行,进入您的项目目录并执行以下命令以下载此Bundle的最新稳定版本
- Symfony <5.4
$ composer require micayael/native-query-from-file-builder-bundle
- Symfony >=5.4
$ composer require micayael/native-query-from-file-builder-bundle:~2.0
此命令要求您已全局安装Composer,具体请参阅Composer文档中的安装章节。
步骤2:启用Bundle
然后,通过将其添加到项目中app/AppKernel.php
文件中注册的Bundle列表来启用此Bundle
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Micayael\NativeQueryFromFileBuilderBundle\NativeQueryFromFileBuilderBundle(), ); // ... } // ... }
配置
使用Symfony Flex的应用程序
native_query_from_file_builder: sql_queries_dir: '%kernel.project_dir%/config/app/queries' # optional (default: '%kernel.project_dir%/config/app/queries') default_connection: default # see your doctrine.yaml to select the connection you want to use by default - optional default: 'default') file_extension: yml # yaml file extension - optional (default: yaml) cache_sql: true # caches sql statements to avoid processing yaml files in each request. Recommended for production - optional (default: true)
- Symfony 5.4
可以通过在对应环境的文件夹内复制文件或使用以下语法来为不同环境定义不同的配置
native_query_from_file_builder: default_connection: secondary_connection cache_sql: true when@dev: native_query_from_file_builder: cache_sql: false
不使用Symfony Flex的应用程序
在app/config/config.yml中添加您的配置