Browse Source

added sp generator get multiple

tags/0.1.3
Robin Thoni 8 years ago
parent
commit
81f4c1bc2c
1 changed files with 18 additions and 1 deletions
  1. 18
    1
      src/Generator/sp.php.twig

+ 18
- 1
src/Generator/sp.php.twig View File

8
 namespace {{ sp_namespace.as_it }};
8
 namespace {{ sp_namespace.as_it }};
9
 
9
 
10
 use Luticate\Utils\LuSpModel;
10
 use Luticate\Utils\LuSpModel;
11
+use Luticate\Utils\LuMultipleDbo;
12
+use Luticate\Utils\LuStringUtils;
11
 use Illuminate\Support\Facades\DB;
13
 use Illuminate\Support\Facades\DB;
12
 
14
 
13
 class {{ sp.sp_name.camel_upper }} extends LuSpModel {
15
 class {{ sp.sp_name.camel_upper }} extends LuSpModel {
25
         return $dbo;
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
     public static function execute({% for arg in args.in %}${{ arg.name.as_it }}{{ loop.last ? "" : ", " }}{% endfor %})
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
 {% if sp.proretset %}
36
 {% if sp.proretset %}
32
         $dboValues = array();
37
         $dboValues = array();
33
         foreach ($values as $value)
38
         foreach ($values as $value)
37
         return self::damToDbo($values[0]);
42
         return self::damToDbo($values[0]);
38
 {% endif %}
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
 {% for arg in args.out %}
57
 {% for arg in args.out %}
41
 
58
 
42
     /**
59
     /**

Loading…
Cancel
Save