소스 검색

added sp generator get multiple

tags/0.1.3
Robin Thoni 8 년 전
부모
커밋
81f4c1bc2c
1개의 변경된 파일18개의 추가작업 그리고 1개의 파일을 삭제
  1. 18
    1
      src/Generator/sp.php.twig

+ 18
- 1
src/Generator/sp.php.twig 파일 보기

@@ -8,6 +8,8 @@
8 8
 namespace {{ sp_namespace.as_it }};
9 9
 
10 10
 use Luticate\Utils\LuSpModel;
11
+use Luticate\Utils\LuMultipleDbo;
12
+use Luticate\Utils\LuStringUtils;
11 13
 use Illuminate\Support\Facades\DB;
12 14
 
13 15
 class {{ sp.sp_name.camel_upper }} extends LuSpModel {
@@ -25,9 +27,12 @@ class {{ sp.sp_name.camel_upper }} extends LuSpModel {
25 27
         return $dbo;
26 28
     }
27 29
 
30
+{% set spcall %}{{ sp.sp_name.as_it }}({% for arg in args.in %}:{{ arg.name.as_it }}{{ loop.last ? "" : ", " }}{% endfor %}){% endset %}
31
+{% set argsarray %}{% for arg in args.in %}":{{ arg.name.as_it }}" => ${{ arg.name.as_it }}{{ loop.last ? "" : ", " }}{% endfor %}{% endset %}
32
+
28 33
     public static function execute({% for arg in args.in %}${{ arg.name.as_it }}{{ loop.last ? "" : ", " }}{% endfor %})
29 34
     {
30
-        $values = DB::select('SELECT * FROM {{ sp.sp_name.as_it }}({% for arg in args.in %}?{{ loop.last ? "" : ", " }}{% endfor %})', array({% for arg in args.in %}${{ arg.name.as_it }}{{ loop.last ? "" : ", " }}{% endfor %}));
35
+        $values = DB::select('SELECT * FROM {{ spcall }}', array({{ argsarray }}));
31 36
 {% if sp.proretset %}
32 37
         $dboValues = array();
33 38
         foreach ($values as $value)
@@ -37,6 +42,18 @@ class {{ sp.sp_name.camel_upper }} extends LuSpModel {
37 42
         return self::damToDbo($values[0]);
38 43
 {% endif %}
39 44
     }
45
+
46
+{% if sp.proretset %}
47
+    public static function getMultipleJson({% for arg in args.in %}${{ arg.name.as_it }}, {% endfor %}$page, $perPage)
48
+    {
49
+        $values = DB::select('SELECT (SELECT count(*) FROM {{ spcall }}) as count, (SELECT json_agg(q) FROM (SELECT * FROM {{ spcall }} OFFSET (:page::int * :perPage::int) LIMIT :perPage) q) as data',
50
+            array({{ argsarray }}, ":page" => $page, ":perPage" => $perPage));
51
+        $value = $values[0];
52
+        $data = LuStringUtils::convertJsonString($value->data);
53
+        return new LuMultipleDbo($value->count, $data);
54
+    }
55
+{% endif %}
56
+
40 57
 {% for arg in args.out %}
41 58
 
42 59
     /**

Loading…
취소
저장