Bladeren bron

增加result->table

ops7503 6 dagen geleden
bovenliggende
commit
f0d084fe4e
2 gewijzigde bestanden met toevoegingen van 10 en 0 verwijderingen
  1. 2 0
      include/db/mysql.h
  2. 8 0
      src/db/mysql.cpp

+ 2 - 0
include/db/mysql.h

@@ -159,6 +159,8 @@ namespace ylib::mysql
         ylib::mysql::row get_row();
         // 当前行转 json 对象
         ylib::json row_to_json();
+
+        ylib::json table();
     private:
         uint32 field_index(const std::string& name) const;
         ylib::mysql::data read_data(uint32 index) const;

+ 8 - 0
src/db/mysql.cpp

@@ -786,6 +786,14 @@ namespace ylib {
         ylib::json result::row_to_json() {
             return get_row().to_json();
         }
+        ylib::json result::table() {
+            ylib::json arr;
+            arr = ylib::json::type::array;
+            while(this->next()){
+                arr.push_back(this->get_row().to_json());
+            }
+            return arr;
+        }
 
 #undef ENSURE_RS