Compare commits

...

642 Commits

Author SHA1 Message Date
as2252258 08fbc49091 eee 2024-08-08 10:52:48 +08:00
as2252258 08e49cfa65 eee 2024-07-10 16:18:27 +08:00
as2252258 d58850b158 eee 2024-07-08 12:06:41 +08:00
as2252258 aba45e8cb9 eee 2024-07-08 10:58:52 +08:00
as2252258 ed22201bef eee 2024-07-02 21:38:30 +08:00
as2252258 ccbac52a16 eee 2024-05-01 02:06:14 +08:00
as2252258 9fe0698d1c eee 2024-05-01 02:02:58 +08:00
as2252258 55e1f6235e eee 2024-05-01 01:54:38 +08:00
as2252258 ed0d044223 eee 2024-04-29 21:55:31 +08:00
as2252258 2b85cb4ec3 eee 2024-04-29 21:55:19 +08:00
as2252258 73b9923740 eee 2024-04-29 21:49:08 +08:00
as2252258 b2c8160314 eee 2024-04-26 17:01:25 +08:00
as2252258 199312d326 eee 2024-04-26 15:39:13 +08:00
as2252258 87f568bdfe eee 2024-04-26 15:36:55 +08:00
as2252258 2fd37f90a3 eee 2024-04-26 15:28:40 +08:00
as2252258 c100190155 eee 2024-04-26 15:27:11 +08:00
as2252258 71766ee914 eee 2024-04-26 15:26:10 +08:00
as2252258 3a39eaabf4 eee 2024-04-26 15:25:12 +08:00
as2252258 722b286f91 eee 2024-04-26 15:23:37 +08:00
as2252258 f9ee3aa014 eee 2024-04-26 15:22:16 +08:00
as2252258 4341efcb8c eee 2024-04-26 15:20:22 +08:00
as2252258 8acf74c9ed eee 2024-04-26 15:15:36 +08:00
as2252258 b9750d743b eee 2024-04-26 15:12:31 +08:00
as2252258 ea34371652 eee 2024-04-16 17:24:22 +08:00
as2252258 92f0c1a973 eee 2024-01-10 18:12:39 +08:00
as2252258 11ad7217c2 eee 2024-01-10 18:08:41 +08:00
as2252258 b647716f1c eee 2024-01-10 18:07:40 +08:00
as2252258 d8b2d1ca2c eee 2024-01-10 17:59:05 +08:00
as2252258 a439c616b4 eee 2024-01-10 17:48:54 +08:00
as2252258 d036e440cd eee 2024-01-10 17:43:10 +08:00
as2252258 88fb563c99 eee 2024-01-10 17:35:55 +08:00
as2252258 1066aa03e8 eee 2023-12-26 17:41:03 +08:00
as2252258 609e5d4749 eee 2023-12-26 17:40:48 +08:00
as2252258 ea8060b047 eee 2023-12-22 11:49:35 +08:00
as2252258 29b3accadb eee 2023-12-22 11:41:55 +08:00
as2252258 22a04814dc eee 2023-12-22 11:41:24 +08:00
as2252258 bb875bd672 eee 2023-12-20 21:05:54 +08:00
as2252258 c2a5d7c5e3 e 2023-12-20 20:56:48 +08:00
as2252258 797d44f816 eee 2023-12-20 18:03:36 +08:00
as2252258 2d067b9d6a eee 2023-12-20 17:26:58 +08:00
as2252258 666dce01bc eee 2023-12-20 17:21:25 +08:00
as2252258 8174848de6 eee 2023-12-18 23:17:26 +08:00
as2252258 d2acc197da eee 2023-12-18 23:16:09 +08:00
as2252258 c0ff5be651 eee 2023-12-18 23:14:52 +08:00
as2252258 b77e4be3e8 eee 2023-12-18 22:00:50 +08:00
as2252258 dc34638a31 eee 2023-12-18 21:59:43 +08:00
as2252258 b94f654ad0 eee 2023-12-18 18:36:08 +08:00
as2252258 9b249e538b eee 2023-12-18 18:11:58 +08:00
as2252258 4bcd4a8a44 eee 2023-12-18 17:59:42 +08:00
as2252258 8c3cc60cc3 eee 2023-12-18 17:40:01 +08:00
as2252258 2ea6d3705d eee 2023-12-18 17:39:43 +08:00
as2252258 1ede0aa3bd eee 2023-12-18 17:12:52 +08:00
as2252258 3d37e11497 eee 2023-12-18 17:11:57 +08:00
as2252258 7f98be6b1c eee 2023-12-18 16:09:21 +08:00
as2252258 abb561f185 eee 2023-12-18 16:03:24 +08:00
as2252258 6b96e54ab0 eee 2023-12-18 15:46:06 +08:00
as2252258 c9255a6c2b eee 2023-12-18 15:11:04 +08:00
as2252258 7d06791d67 eee 2023-12-18 15:01:08 +08:00
as2252258 e248bbbea0 eee 2023-12-14 09:50:49 +08:00
as2252258 694028f983 eee 2023-12-13 19:09:09 +08:00
as2252258 4fbbbe0cfe eee 2023-12-13 19:05:44 +08:00
as2252258 0833e87362 eee 2023-12-13 18:34:48 +08:00
as2252258 8cd195f4ee eee 2023-12-13 18:27:12 +08:00
as2252258 b690228ea2 eee 2023-12-13 18:25:06 +08:00
as2252258 0e20ab2167 eee 2023-12-13 18:23:24 +08:00
as2252258 8685e039a4 eee 2023-12-13 18:19:36 +08:00
as2252258 d28af2fa09 eee 2023-12-13 18:14:42 +08:00
as2252258 89592ff638 eee 2023-12-13 18:07:39 +08:00
as2252258 b490e85a34 eee 2023-12-13 17:50:42 +08:00
as2252258 2d1d780618 eee 2023-12-13 17:48:07 +08:00
as2252258 3e73149716 eee 2023-12-13 17:43:25 +08:00
as2252258 a1d42a0831 eee 2023-12-13 17:25:40 +08:00
as2252258 1092273257 eee 2023-12-13 17:08:31 +08:00
as2252258 f614795f95 eee 2023-12-13 17:07:01 +08:00
as2252258 79b7bb432f eee 2023-12-13 17:02:29 +08:00
as2252258 9a670f626e eee 2023-12-13 16:25:17 +08:00
as2252258 109cc2ac27 eee 2023-12-13 16:24:11 +08:00
as2252258 3ab08c9ca7 eee 2023-12-13 16:22:25 +08:00
as2252258 c84d9f8328 eee 2023-12-13 16:19:16 +08:00
as2252258 658445927a eee 2023-12-13 16:18:12 +08:00
as2252258 a73b5c0e2a eee 2023-12-13 15:36:51 +08:00
as2252258 3179e95a82 eee 2023-12-13 14:47:23 +08:00
as2252258 85eaeba8ba eee 2023-12-13 10:14:26 +08:00
as2252258 16fe127019 eee 2023-12-13 10:05:42 +08:00
as2252258 013be605f4 eee 2023-12-13 09:47:00 +08:00
as2252258 64087d6258 eee 2023-12-12 17:47:40 +08:00
as2252258 9c433855d5 eee 2023-12-12 17:46:25 +08:00
as2252258 fd71d23802 eee 2023-12-12 17:40:51 +08:00
as2252258 2eb63c6bd4 eee 2023-12-12 17:21:25 +08:00
as2252258 e2c0f62532 eee 2023-12-12 15:35:35 +08:00
as2252258 510a13e3da eee 2023-12-06 18:33:25 +08:00
as2252258 1b1eec5f78 eee 2023-12-06 18:32:21 +08:00
as2252258 0b782de1f1 eee 2023-12-06 18:24:53 +08:00
as2252258 641187e240 eee 2023-12-06 18:23:11 +08:00
as2252258 501ace9e36 eee 2023-11-30 17:02:20 +08:00
as2252258 c352c46a0f eee 2023-11-24 11:01:07 +08:00
as2252258 fec858ffbd eee 2023-11-24 10:46:44 +08:00
as2252258 c119186ad4 eee 2023-11-24 10:38:18 +08:00
as2252258 66d5d46add eee 2023-11-23 15:30:57 +08:00
as2252258 d42e30ecbe eee 2023-11-23 15:27:57 +08:00
as2252258 f8a1e700a7 eee 2023-11-23 15:26:20 +08:00
as2252258 53dbf7a9b2 eee 2023-11-14 15:01:30 +08:00
as2252258 a1238613f9 eee 2023-11-13 17:52:38 +08:00
as2252258 dcf4e0a614 eee 2023-10-24 17:22:29 +08:00
as2252258 b0e627c4fb eee 2023-10-24 15:14:46 +08:00
as2252258 67c7dd8421 eee 2023-10-12 00:46:07 +08:00
as2252258 d097b66187 eee 2023-10-12 00:18:54 +08:00
as2252258 82f38732ef eee 2023-10-11 23:51:54 +08:00
as2252258 e1e5af2173 eee 2023-10-07 20:40:59 +08:00
as2252258 4b304e52a2 eee 2023-10-05 15:48:35 +08:00
as2252258 77419f2d10 eee 2023-10-05 15:47:39 +08:00
as2252258 2fb2111526 eee 2023-10-05 15:33:18 +08:00
as2252258 0c2134a361 eee 2023-10-05 15:23:15 +08:00
as2252258 d942db93d8 eee 2023-10-05 15:15:50 +08:00
as2252258 0dd7b7e0e7 eee 2023-09-30 20:22:49 +08:00
as2252258 34ad1f58fe eee 2023-09-30 20:22:24 +08:00
as2252258 f9a9652726 eee 2023-09-30 20:21:10 +08:00
as2252258 ba59b9431e eee 2023-09-30 20:12:28 +08:00
as2252258 fc73dbf98d eee 2023-09-30 20:11:03 +08:00
as2252258 d4b9dd6758 eee 2023-09-30 20:10:07 +08:00
as2252258 b5b5db4d2c eee 2023-09-30 20:09:18 +08:00
as2252258 735801f756 eee 2023-09-30 20:03:37 +08:00
as2252258 fd8ac37742 eee 2023-09-30 20:03:15 +08:00
as2252258 4cac66b1d1 eee 2023-09-30 19:56:58 +08:00
as2252258 bc43a32b10 eee 2023-09-30 19:56:02 +08:00
as2252258 f61c678d54 eee 2023-09-30 19:53:44 +08:00
as2252258 beb541f01b eee 2023-09-30 19:50:33 +08:00
as2252258 bae4e54dd5 eee 2023-09-30 19:44:05 +08:00
as2252258 f477b181de eee 2023-09-30 19:43:07 +08:00
as2252258 5b3b16e4f6 eee 2023-09-30 19:40:42 +08:00
as2252258 28451d6e02 eee 2023-09-30 19:36:07 +08:00
as2252258 a0871d9cbd eee 2023-09-30 19:35:46 +08:00
as2252258 313092dd75 eee 2023-09-30 19:32:41 +08:00
as2252258 6be1180962 eee 2023-09-11 11:02:34 +08:00
as2252258 370c50f1fe eee 2023-09-01 10:56:06 +08:00
as2252258 ba68102405 eee 2023-09-01 10:54:55 +08:00
as2252258 2ee482241d eee 2023-09-01 10:53:38 +08:00
as2252258 0bff75446d eee 2023-08-31 12:29:02 +08:00
as2252258 a3fa4521fc eee 2023-08-30 23:25:21 +08:00
as2252258 1d37abf5d5 eee 2023-08-29 22:47:48 +08:00
as2252258 a2ceb7310e eee 2023-08-29 22:27:47 +08:00
as2252258 2b902f3624 eee 2023-08-29 22:21:42 +08:00
as2252258 c036cea809 eee 2023-08-29 22:20:30 +08:00
as2252258 91edb08238 eee 2023-08-29 22:13:37 +08:00
as2252258 5158b709bd eee 2023-08-29 21:54:02 +08:00
as2252258 9c8c8c6bb3 eee 2023-08-29 21:46:05 +08:00
as2252258 cc723a7630 eee 2023-08-29 21:43:37 +08:00
as2252258 138549f54d eee 2023-08-29 21:39:04 +08:00
as2252258 99ff8b1ed5 eee 2023-08-29 21:35:57 +08:00
as2252258 2feff52291 eee 2023-08-29 21:35:19 +08:00
as2252258 e08e811580 eee 2023-08-29 15:19:39 +08:00
as2252258 6f979394a3 qqq 2023-08-25 10:28:47 +08:00
as2252258 9eb7a11b6c qqq 2023-08-25 10:21:56 +08:00
as2252258 e6b7b5ee57 qqq 2023-08-25 10:21:35 +08:00
as2252258 666de7ce40 qqq 2023-08-25 10:10:09 +08:00
as2252258 d377deab8e qqq 2023-08-25 10:04:55 +08:00
as2252258 703300182b qqq 2023-08-25 10:01:53 +08:00
as2252258 5caed72909 qqq 2023-08-25 10:00:48 +08:00
as2252258 250cdda33e qqq 2023-08-25 09:37:58 +08:00
as2252258 69b5ef6437 qqq 2023-08-25 00:32:38 +08:00
as2252258 d37f43c4ac qqq 2023-08-25 00:18:44 +08:00
as2252258 5b0e69f190 qqq 2023-08-25 00:17:17 +08:00
as2252258 b81be565ae qqq 2023-08-25 00:16:49 +08:00
as2252258 c30a58a4c5 qqq 2023-08-24 16:04:24 +08:00
as2252258 812505f914 qqq 2023-08-24 16:01:20 +08:00
as2252258 45968536c5 qqq 2023-08-24 14:19:47 +08:00
as2252258 d0375388b4 qqq 2023-08-24 14:15:00 +08:00
as2252258 c3eced973a qqq 2023-08-24 14:14:03 +08:00
as2252258 6cb5899fe1 qqq 2023-08-24 14:13:22 +08:00
as2252258 853f23bb3d qqq 2023-08-24 14:08:55 +08:00
as2252258 1976822784 qqq 2023-08-24 14:07:01 +08:00
as2252258 17a5dcb2bb qqq 2023-08-24 14:06:35 +08:00
as2252258 58cbfce778 qqq 2023-08-24 14:05:00 +08:00
as2252258 c86d6791c9 qqq 2023-08-24 14:02:58 +08:00
as2252258 636c96b73c qqq 2023-08-24 14:01:20 +08:00
as2252258 7f885aca09 qqq 2023-08-24 13:59:44 +08:00
as2252258 8a25e4b7be qqq 2023-08-24 13:56:12 +08:00
as2252258 6dab6eba8c qqq 2023-08-24 13:49:58 +08:00
as2252258 b1ac46f14f qqq 2023-08-24 13:41:27 +08:00
as2252258 36e768e3e6 qqq 2023-08-24 12:29:18 +08:00
as2252258 327f40faea qqq 2023-08-24 12:11:35 +08:00
as2252258 d3dacf96df qqq 2023-08-24 12:11:23 +08:00
as2252258 76d75806e5 qqq 2023-08-24 12:10:08 +08:00
as2252258 677bda01a0 qqq 2023-08-24 12:06:54 +08:00
as2252258 2c63caaaf8 qqq 2023-08-24 12:06:35 +08:00
as2252258 0bb294edc5 qqq 2023-08-24 12:01:34 +08:00
as2252258 e06c04a5bb qqq 2023-08-24 11:55:43 +08:00
as2252258 8b35064395 qqq 2023-08-24 11:46:27 +08:00
as2252258 8f69385eaa qqq 2023-08-24 11:42:03 +08:00
as2252258 a85fc58630 qqq 2023-08-24 11:25:42 +08:00
as2252258 2e01419960 qqq 2023-08-23 01:48:34 +08:00
as2252258 543995f5cd qqq 2023-08-23 01:48:18 +08:00
as2252258 4b55ee837e qqq 2023-08-21 16:56:19 +08:00
as2252258 2493b4e15d qqq 2023-08-21 16:47:30 +08:00
as2252258 d9ffa9dae2 qqq 2023-08-21 16:44:54 +08:00
as2252258 37c9bcc4d2 qqq 2023-08-21 09:38:37 +08:00
as2252258 0d3a37084e qqq 2023-08-19 19:48:10 +08:00
as2252258 6283d6cd49 qqq 2023-08-18 15:05:05 +08:00
as2252258 1fb13aa3a3 qqq 2023-08-18 15:04:39 +08:00
as2252258 0ea9339816 qqq 2023-08-17 17:41:26 +08:00
as2252258 1318c9e5b3 qqq 2023-08-17 17:33:55 +08:00
as2252258 05f90fe4a4 qqq 2023-08-17 17:33:28 +08:00
as2252258 c30c830169 qqq 2023-08-17 17:32:36 +08:00
as2252258 bbd4d7b353 qqq 2023-08-17 17:30:53 +08:00
as2252258 c718e852dd qqq 2023-08-17 17:24:46 +08:00
as2252258 77648f3878 qqq 2023-08-17 17:23:30 +08:00
as2252258 7015e39fa6 qqq 2023-08-17 11:31:54 +08:00
as2252258 ccacfcbc02 qqq 2023-08-17 10:16:08 +08:00
as2252258 37abaa8035 qqq 2023-08-17 09:48:44 +08:00
as2252258 c208d023e7 qqq 2023-08-16 16:38:33 +08:00
as2252258 add36ab75c qqq 2023-08-16 16:35:54 +08:00
as2252258 321c256100 qqq 2023-08-16 16:33:56 +08:00
as2252258 f6cd6756ce qqq 2023-08-16 16:18:03 +08:00
as2252258 ce7539ab62 qqq 2023-08-16 16:16:29 +08:00
as2252258 3ba95cc3dd qqq 2023-08-16 16:14:41 +08:00
as2252258 745a5820ba qqq 2023-08-16 16:11:56 +08:00
as2252258 373a1b0fed qqq 2023-08-16 15:55:50 +08:00
as2252258 720c5498f1 qqq 2023-08-16 15:51:56 +08:00
as2252258 9a680d56a7 qqq 2023-08-16 14:54:02 +08:00
as2252258 1d2bca40a2 qqq 2023-08-16 14:47:26 +08:00
as2252258 4c49a09047 qqq 2023-08-16 14:39:46 +08:00
as2252258 e597224e86 qqq 2023-08-16 14:32:06 +08:00
as2252258 2a83160792 qqq 2023-08-16 14:30:52 +08:00
as2252258 b3759bfa53 qqq 2023-08-16 14:30:39 +08:00
as2252258 9f51ff4659 qqq 2023-08-16 14:29:39 +08:00
as2252258 a264b2b8a3 qqq 2023-08-16 14:25:48 +08:00
as2252258 be09229577 qqq 2023-08-16 14:25:19 +08:00
as2252258 25296ee714 qqq 2023-08-16 14:22:38 +08:00
as2252258 6678011261 qqq 2023-08-16 14:18:09 +08:00
as2252258 17b194f50c qqq 2023-08-16 12:36:45 +08:00
as2252258 b77e6a7618 qqq 2023-08-16 12:34:56 +08:00
as2252258 aa14ff3376 qqq 2023-08-16 12:27:03 +08:00
as2252258 e5c5ce822c qqq 2023-08-16 12:19:47 +08:00
as2252258 68035a95e4 qqq 2023-08-16 12:15:59 +08:00
as2252258 5f5b90ac49 qqq 2023-08-16 12:00:10 +08:00
as2252258 ed749d7a34 qqq 2023-08-16 10:26:48 +08:00
as2252258 bec9cd1a3f qqq 2023-08-16 01:01:47 +08:00
as2252258 55bb55f955 qqq 2023-08-16 00:57:33 +08:00
as2252258 5b3b3b7a6b qqq 2023-08-16 00:55:05 +08:00
as2252258 e1c893c4e1 qqq 2023-08-16 00:43:39 +08:00
as2252258 0267b9ca11 qqq 2023-08-16 00:39:55 +08:00
as2252258 a95f2af9ed qqq 2023-08-15 23:50:26 +08:00
as2252258 4a51a8a336 qqq 2023-08-14 18:56:45 +08:00
as2252258 0a567634d6 qqq 2023-08-14 14:14:40 +08:00
as2252258 08e9211e0e qqq 2023-08-14 14:03:30 +08:00
as2252258 d42d284f62 qqq 2023-08-14 14:02:16 +08:00
as2252258 63ddc36958 qqq 2023-08-14 12:41:16 +08:00
as2252258 3d0fd3d5d0 qqq 2023-08-12 00:14:39 +08:00
as2252258 4c27cae802 qqq 2023-08-11 23:06:14 +08:00
as2252258 dc73de9abd qqq 2023-08-11 14:02:51 +08:00
as2252258 d96f1c27a5 qqq 2023-08-02 14:46:01 +08:00
as2252258 bc36df50f8 qqq 2023-08-02 14:37:59 +08:00
as2252258 2c893a52d5 qqq 2023-07-31 23:28:59 +08:00
as2252258 e575254139 qqq 2023-07-31 23:26:58 +08:00
as2252258 00a2125efc qqq 2023-07-31 23:08:59 +08:00
as2252258 45d0712cb2 qqq 2023-07-31 15:57:15 +08:00
as2252258 8eb4f5869f qqq 2023-07-27 22:59:12 +08:00
as2252258 29aae506c1 qqq 2023-07-27 22:59:00 +08:00
as2252258 9ab0aa1fe7 qqq 2023-07-26 11:00:08 +08:00
as2252258 4abc1a621b qqq 2023-07-25 09:33:24 +08:00
as2252258 4c6dbc9b3c qqq 2023-07-20 15:01:24 +08:00
as2252258 d4219b902a qqq 2023-07-14 23:25:41 +08:00
as2252258 83138dbcb4 qqq 2023-07-13 10:37:14 +08:00
as2252258 9d7605b8e4 qqq 2023-07-10 11:28:53 +08:00
as2252258 203eda17ad qqq 2023-07-10 11:26:35 +08:00
as2252258 1c07e59357 qqq 2023-07-10 11:23:38 +08:00
as2252258 a4a5025e95 qqq 2023-07-10 11:20:55 +08:00
as2252258 3da1c718d9 qqq 2023-07-10 11:14:26 +08:00
as2252258 51039961c1 qqq 2023-07-06 13:33:50 +08:00
as2252258 a403421bfe qqq 2023-06-12 15:34:08 +08:00
as2252258 5d161fd1e7 qqq 2023-06-12 15:31:45 +08:00
as2252258 65bbc6888a qqq 2023-05-26 09:22:34 +08:00
as2252258 c8159194bf qqq 2023-05-26 09:20:29 +08:00
as2252258 49742a08ad qqq 2023-05-25 17:00:58 +08:00
as2252258 efa6cf5421 qqq 2023-05-25 16:59:18 +08:00
as2252258 ac443a49b1 qqq 2023-05-25 16:38:12 +08:00
as2252258 c57e606e55 qqq 2023-05-20 23:05:38 +08:00
as2252258 4f6952bdc5 r 2023-05-02 15:43:20 +08:00
as2252258 ae5e86c7e2 ed 2023-05-02 15:37:10 +08:00
as2252258 027ac6f25b 变更 2023-04-25 23:12:51 +08:00
as2252258 6ff252fe2a 变更 2023-04-25 23:09:16 +08:00
as2252258 e747a988ff 变更 2023-04-25 23:05:54 +08:00
as2252258 b6629987ab 变更 2023-04-25 22:50:21 +08:00
as2252258 8529a8eb0d 变更 2023-04-25 22:48:45 +08:00
as2252258 5e4beed63c 变更 2023-04-25 22:11:40 +08:00
as2252258 def1e1e9c1 变更 2023-04-25 18:04:31 +08:00
as2252258 3a577aaf03 变更 2023-04-25 17:39:27 +08:00
as2252258 7d8ed087f5 变更 2023-04-25 17:36:21 +08:00
as2252258 84568c504a 变更 2023-04-25 17:05:06 +08:00
as2252258 1793fa3667 变更 2023-04-23 11:00:05 +08:00
as2252258 bb9112d3b5 变更 2023-04-23 10:41:42 +08:00
as2252258 688f188d7c 变更 2023-04-21 17:15:13 +08:00
as2252258 711750dba3 变更 2023-04-20 23:22:53 +08:00
as2252258 eedfbb900e 变更 2023-04-20 23:16:36 +08:00
as2252258 d65d7b0d87 变更 2023-04-20 23:08:10 +08:00
as2252258 08f664e136 变更 2023-04-20 22:41:25 +08:00
as2252258 d2029e94a0 变更 2023-04-20 22:37:22 +08:00
as2252258 af966999d0 变更 2023-04-19 21:39:55 +08:00
as2252258 ed0035a707 变更 2023-04-19 10:51:08 +08:00
as2252258 ebbc3368bd 变更 2023-04-18 23:47:30 +08:00
as2252258 7472217482 变更 2023-04-17 11:03:22 +08:00
as2252258 e2c6c2ae46 变更 2023-04-17 10:59:27 +08:00
as2252258 2486bfd4d1 变更 2023-04-17 10:57:38 +08:00
as2252258 1b65f84962 变更 2023-04-17 10:56:35 +08:00
as2252258 5057135590 变更 2023-04-17 10:34:23 +08:00
as2252258 ec1c68be39 变更 2023-04-17 10:27:32 +08:00
as2252258 e47e3f8514 变更 2023-04-17 10:25:01 +08:00
as2252258 8c6f9676b5 变更 2023-04-17 10:18:59 +08:00
as2252258 409f75eff6 变更 2023-04-17 01:39:31 +08:00
as2252258 2e258c7e08 变更 2023-04-16 15:34:50 +08:00
as2252258 64d3f31138 变更 2023-04-16 14:41:20 +08:00
as2252258 0bf69d576d 变更 2023-04-16 02:46:54 +08:00
as2252258 d22955233c 变更 2023-04-16 02:01:26 +08:00
as2252258 f6d4b0fbca 变更 2023-04-16 01:45:33 +08:00
as2252258 3cd2e8d889 变更 2023-04-16 00:59:31 +08:00
as2252258 5600ede420 变更 2023-04-12 10:08:11 +08:00
as2252258 6aac4ac878 变更 2023-04-12 10:07:45 +08:00
as2252258 522d9233ca 变更 2023-04-11 23:49:00 +08:00
as2252258 b8906ef54f 变更 2023-04-11 18:59:17 +08:00
as2252258 fadd7501ee 变更 2023-04-11 18:36:43 +08:00
as2252258 9ab58b43f9 变更 2023-04-11 18:09:29 +08:00
as2252258 ea780bda4a 变更 2023-04-11 18:03:08 +08:00
as2252258 a489d465a7 变更 2023-04-11 18:02:44 +08:00
as2252258 c64e05a81e 变更 2023-04-11 17:05:03 +08:00
as2252258 3b7dd9c709 变更 2023-04-10 18:56:36 +08:00
as2252258 5b3e2bb569 变更 2023-04-10 17:53:20 +08:00
as2252258 ecfe15c3ac 变更 2023-04-10 17:45:29 +08:00
as2252258 b069bc425b 变更 2023-04-10 17:42:12 +08:00
as2252258 a7d8ee83ee 变更 2023-04-10 17:39:36 +08:00
as2252258 f8f22c39c4 变更 2023-04-10 17:35:59 +08:00
as2252258 fdf696624c 变更 2023-04-10 17:34:19 +08:00
as2252258 e002e4b4d0 变更 2023-04-10 17:26:28 +08:00
as2252258 ee8b5fba20 变更 2023-04-10 17:20:48 +08:00
as2252258 94ebb18b7e 变更 2023-04-10 17:13:24 +08:00
as2252258 aaa3fba8ba 变更 2023-04-10 11:36:33 +08:00
as2252258 c77b2ef3eb 变更 2023-04-10 11:19:37 +08:00
as2252258 37009c3f59 变更 2023-04-07 21:57:47 +08:00
as2252258 f7f855d279 变更 2023-04-07 21:54:22 +08:00
as2252258 ad43d02673 变更 2023-04-07 21:47:15 +08:00
as2252258 521fe64b62 变更 2023-04-07 21:45:47 +08:00
as2252258 0a6fbed5d0 变更 2023-04-07 21:41:49 +08:00
as2252258 44d350cfea 变更 2023-04-07 21:37:14 +08:00
as2252258 2170ea7d29 变更 2023-04-07 21:23:38 +08:00
as2252258 33fa378018 变更 2023-04-07 21:20:30 +08:00
as2252258 478106c6f7 变更 2023-04-07 21:13:01 +08:00
as2252258 12d3d05001 变更 2023-04-07 21:10:44 +08:00
as2252258 ebf6862834 变更 2023-04-07 19:00:37 +08:00
as2252258 2153481f69 变更 2023-04-07 18:56:17 +08:00
as2252258 b2807ffe6f 变更 2023-04-07 18:50:26 +08:00
as2252258 b4041de60b 变更 2023-04-07 18:50:02 +08:00
as2252258 5c24528957 变更 2023-04-07 18:35:29 +08:00
as2252258 7833abe644 变更 2023-04-07 18:32:27 +08:00
as2252258 7a782322b5 变更 2023-04-07 18:29:48 +08:00
as2252258 5d41c7219f 变更 2023-04-07 18:23:27 +08:00
as2252258 6d122c4ae1 变更 2023-04-07 18:00:25 +08:00
as2252258 66ecf2585a 变更 2023-04-07 00:11:28 +08:00
as2252258 84f7346d49 变更 2023-04-06 23:08:12 +08:00
as2252258 d3772c0134 变更 2023-04-06 23:07:22 +08:00
as2252258 ff751db14c 变更 2023-04-06 23:01:18 +08:00
as2252258 7fc9a5a908 变更 2023-04-06 22:59:04 +08:00
as2252258 6fe699413d 变更 2023-04-06 22:58:43 +08:00
as2252258 84d1701ff7 变更 2023-04-06 22:55:34 +08:00
as2252258 5a96ca96cc 变更 2023-04-06 22:54:50 +08:00
as2252258 4e978cf919 变更 2023-04-06 22:47:34 +08:00
as2252258 b9dae95149 变更 2023-04-06 22:45:34 +08:00
as2252258 fe1711325b 变更 2023-04-06 22:43:43 +08:00
as2252258 3d8c01a42c 变更 2023-04-06 22:39:31 +08:00
as2252258 4843abfdfa 变更 2023-04-06 22:20:08 +08:00
as2252258 919ed98422 变更 2023-04-06 22:19:45 +08:00
as2252258 a8924c270b 变更 2023-04-06 18:21:55 +08:00
as2252258 582583cd32 变更 2023-04-05 22:09:13 +08:00
as2252258 dd65dfbd17 变更 2023-04-05 21:46:54 +08:00
as2252258 ffc8cd7a33 变更 2023-04-05 20:27:00 +08:00
as2252258 9bb8582aee 变更 2023-04-05 20:19:05 +08:00
as2252258 ca516ee766 变更 2023-04-05 20:15:40 +08:00
as2252258 03c908e4da 变更 2023-04-05 14:09:46 +08:00
as2252258 b75204e53e 变更 2023-04-05 14:06:00 +08:00
as2252258 b5a7dfa98e 变更 2023-04-05 13:58:31 +08:00
as2252258 81c2b0e114 变更 2023-04-05 13:49:17 +08:00
as2252258 f6c87aadaf 变更 2023-04-05 12:35:18 +08:00
as2252258 225af0038d 变更 2023-04-05 11:08:34 +08:00
as2252258 f52609844c 变更 2023-04-05 11:06:45 +08:00
as2252258 6a673152c1 变更 2023-04-05 10:53:28 +08:00
as2252258 3ecc781002 变更 2023-04-05 10:50:17 +08:00
as2252258 732b922a4c 变更 2023-04-05 10:26:28 +08:00
as2252258 c86eb1a83d 变更 2023-04-05 10:15:50 +08:00
as2252258 bc3c286416 变更 2023-04-05 09:53:32 +08:00
as2252258 5c6663c002 变更 2023-04-04 14:49:43 +08:00
as2252258 dd0eb233bb 变更 2023-04-04 14:49:26 +08:00
as2252258 1370891b93 变更 2023-04-04 14:44:09 +08:00
as2252258 a25634f07a 变更 2023-04-04 14:38:27 +08:00
as2252258 5064e5d683 变更 2023-04-04 14:29:33 +08:00
as2252258 e55eb19768 变更 2023-04-04 14:26:11 +08:00
as2252258 faed634616 变更 2023-04-03 17:56:12 +08:00
as2252258 1d7ffcda89 变更 2023-04-03 17:40:44 +08:00
as2252258 92ab70d59d 变更 2023-04-03 17:30:07 +08:00
as2252258 4e109ffdf8 变更 2023-04-03 13:45:59 +08:00
as2252258 7eb80d607b 变更 2023-04-03 11:08:11 +08:00
as2252258 6d646ea2a3 变更 2023-04-03 00:43:06 +08:00
as2252258 3c240efa7a 变更 2023-04-03 00:37:30 +08:00
as2252258 59cf5e7d64 变更 2023-04-02 23:58:50 +08:00
as2252258 aafb0dd5e0 变更 2023-04-02 23:31:33 +08:00
as2252258 d9fd802312 变更 2023-04-02 23:28:23 +08:00
as2252258 cd9327f5c2 变更 2023-04-02 23:23:55 +08:00
as2252258 f1faeb038f 变更 2023-04-02 23:07:16 +08:00
as2252258 f3a863f55c 变更 2023-04-02 20:13:56 +08:00
as2252258 0a323b5f62 变更 2023-04-02 20:13:19 +08:00
as2252258 735c077f46 变更 2023-04-02 20:09:40 +08:00
as2252258 0f28608180 变更 2023-04-02 20:03:19 +08:00
as2252258 67fdee8fd9 变更 2023-04-02 19:57:48 +08:00
as2252258 f554b4c81e 变更 2023-04-02 19:53:43 +08:00
as2252258 685a0d72b2 变更 2023-04-02 01:26:10 +08:00
as2252258 69648e3373 变更 2023-04-02 01:23:48 +08:00
as2252258 555ef93965 变更 2023-04-02 01:21:39 +08:00
as2252258 4fd91f5f4f 变更 2023-04-01 21:05:50 +08:00
as2252258 0450226d36 变更 2023-04-01 21:04:28 +08:00
as2252258 eac2800561 变更 2023-04-01 20:57:07 +08:00
as2252258 6493bf91bf 变更 2023-04-01 20:48:03 +08:00
as2252258 1dfe32bf3c 变更 2023-04-01 18:50:44 +08:00
as2252258 cd94d2dc57 变更 2023-04-01 17:11:47 +08:00
as2252258 2aec2afc59 变更 2023-04-01 16:03:02 +08:00
as2252258 509eabe78e 变更 2023-04-01 15:58:17 +08:00
as2252258 c805173600 变更 2023-04-01 15:56:45 +08:00
as2252258 9b1489f576 变更 2023-04-01 15:54:38 +08:00
as2252258 e2f94c9202 变更 2023-04-01 01:27:57 +08:00
as2252258 98fff7302e 变更 2023-04-01 00:37:52 +08:00
as2252258 afec8be942 变更 2023-04-01 00:32:04 +08:00
as2252258 0f911db7ee 变更 2023-04-01 00:29:28 +08:00
as2252258 f17b163f83 变更 2023-04-01 00:27:08 +08:00
as2252258 79db796ba3 变更 2023-04-01 00:25:22 +08:00
as2252258 c165f5f205 变更 2023-03-31 23:36:07 +08:00
as2252258 656753cf60 变更 2023-03-31 11:09:12 +08:00
as2252258 783703eb0f 变更 2023-03-31 10:37:15 +08:00
as2252258 104ddcc34a 变更 2023-03-31 10:31:50 +08:00
as2252258 ff27c0de65 变更 2023-03-30 23:50:51 +08:00
as2252258 32ab38d5cd 变更 2023-03-30 23:46:00 +08:00
as2252258 24d8959aaf 变更 2023-03-30 23:42:55 +08:00
as2252258 5c9f92f955 变更 2023-03-30 20:39:00 +08:00
as2252258 bfa39c3669 变更 2023-03-30 18:59:50 +08:00
as2252258 af3e6d580e 变更 2023-02-13 17:00:32 +08:00
as2252258 677bb7ad42 变更 2023-02-13 16:47:50 +08:00
as2252258 8d1c0d056f 变更 2023-02-13 14:37:07 +08:00
as2252258 ed24164680 变更 2023-02-13 14:27:28 +08:00
as2252258 59e25c1648 变更 2023-02-13 14:23:28 +08:00
as2252258 97d8f8fac5 变更 2023-02-10 10:56:19 +08:00
as2252258 17e51b7898 变更 2023-02-08 17:33:07 +08:00
as2252258 dba7d6085a 变更 2023-02-07 17:44:02 +08:00
as2252258 add511ed2a 变更 2023-02-07 17:05:21 +08:00
as2252258 dfbfa701e5 变更 2023-02-07 17:01:45 +08:00
as2252258 73561a8983 变更 2023-02-07 16:46:13 +08:00
as2252258 603e0a41fc 变更 2023-02-07 15:17:08 +08:00
as2252258 728b253c0b 变更 2023-02-06 14:10:54 +08:00
as2252258 5cc86e0f0c 变更 2023-02-06 14:08:38 +08:00
as2252258 3c73bc89ba 变更 2023-02-06 14:04:40 +08:00
as2252258 564877c579 变更 2023-02-06 14:01:06 +08:00
as2252258 007c40a0eb 变更 2023-02-06 13:54:53 +08:00
as2252258 f86d155059 变更 2023-01-30 11:03:58 +08:00
as2252258 767288886f 变更 2022-12-12 17:31:12 +08:00
as2252258 78200ebffd 变更 2022-12-12 15:04:11 +08:00
as2252258 707e13609f 变更 2022-12-12 11:27:34 +08:00
as2252258 d53b001ef7 变更 2022-12-12 11:19:27 +08:00
as2252258 77f63a85ed 变更 2022-09-29 23:06:07 +08:00
as2252258 76154631e5 变更 2022-09-29 22:58:43 +08:00
as2252258 62f3747701 变更 2022-09-29 22:53:39 +08:00
as2252258 f87a3c386f 变更 2022-09-29 22:51:41 +08:00
as2252258 7554f6b161 变更 2022-09-29 22:38:25 +08:00
as2252258 322168ff68 变更 2022-09-29 18:58:32 +08:00
as2252258 02eddb98a2 变更 2022-09-29 18:54:14 +08:00
as2252258 fc828df683 变更 2022-09-21 14:40:24 +08:00
as2252258 1bc5e49b42 变更 2022-09-21 14:27:26 +08:00
as2252258 4a654821a1 变更 2022-09-20 18:53:49 +08:00
as2252258 dbf33b6d7d 变更 2022-09-20 18:35:20 +08:00
as2252258 202852a95d 变更 2022-09-20 18:34:10 +08:00
as2252258 72cfba6a5d 变更 2022-09-20 18:33:03 +08:00
as2252258 145970316f 变更 2022-09-20 18:23:19 +08:00
as2252258 58c3b38c73 变更 2022-09-20 18:15:50 +08:00
as2252258 4dc55fd772 变更 2022-09-20 11:17:59 +08:00
as2252258 41bce52883 变更 2022-09-19 18:39:28 +08:00
as2252258 17c8d45349 变更 2022-09-19 18:24:12 +08:00
as2252258 91cc3c0613 变更 2022-09-18 03:34:13 +08:00
as2252258 ca011c4557 change delete returned 2022-09-12 02:49:18 +08:00
as2252258 9d81bc6479 变更 2022-09-07 14:36:32 +08:00
as2252258 c7ad5123e2 变更 2022-09-07 14:31:10 +08:00
as2252258 e3169b1348 Merge branch 'master' of github.com:as2252258/kiri-databases 2022-09-02 16:40:17 +08:00
as2252258 8f20d59ff8 变更 2022-09-02 16:39:17 +08:00
as2252258 1c287da18d 变更 2022-07-12 02:02:36 +08:00
as2252258 2845c6c1ac 变更 2022-07-12 01:42:32 +08:00
as2252258 e41d03ea27 modify plugin name 2022-07-11 18:53:19 +08:00
as2252258 9fa91a05ef modify plugin name 2022-07-11 18:34:30 +08:00
as2252258 f14b198e25 modify plugin name 2022-07-11 16:28:05 +08:00
as2252258 49cd130c81 modify plugin name 2022-07-11 16:26:51 +08:00
as2252258 e33776314b modify plugin name 2022-07-11 16:26:14 +08:00
as2252258 64fd34a23c modify plugin name 2022-07-11 16:09:57 +08:00
as2252258 bad445aeb6 modify plugin name 2022-07-11 14:54:46 +08:00
as2252258 db97de7e40 modify plugin name 2022-07-11 14:46:46 +08:00
as2252258 531b54edb2 modify plugin name 2022-07-11 14:34:41 +08:00
as2252258 56fdf310c8 modify plugin name 2022-07-11 14:26:49 +08:00
as2252258 c946eed53f modify plugin name 2022-07-11 14:16:16 +08:00
as2252258 bc728071c7 modify plugin name 2022-07-11 14:15:21 +08:00
as2252258 4316e88677 变更 2022-07-10 02:31:30 +08:00
as2252258 7509597582 变更 2022-07-10 01:23:32 +08:00
as2252258 86798409fd 变更 2022-07-10 01:19:09 +08:00
as2252258 bd3eb54a05 变更 2022-07-10 01:09:08 +08:00
as2252258 8f6a639317 变更 2022-07-10 00:41:56 +08:00
as2252258 8796e60285 变更 2022-07-10 00:31:10 +08:00
as2252258 be3ceb8ccc 变更 2022-06-30 16:40:28 +08:00
as2252258 e0fc63d78c 变更 2022-06-23 00:45:43 +08:00
as2252258 0d4a690e28 modify plugin name 2022-06-22 19:16:07 +08:00
as2252258 20eff5c29a modify plugin name 2022-06-22 18:28:46 +08:00
as2252258 c72c5d4e0d modify plugin name 2022-06-22 16:29:42 +08:00
as2252258 e98c67e0c3 modify plugin name 2022-06-20 18:40:14 +08:00
as2252258 a6c59331af modify plugin name 2022-06-17 15:09:10 +08:00
as2252258 1314ccc421 modify plugin name 2022-06-17 15:08:41 +08:00
as2252258 39777985f7 modify plugin name 2022-06-17 14:25:29 +08:00
as2252258 744acdc826 modify plugin name 2022-06-17 14:11:26 +08:00
as2252258 cf79882a8f modify plugin name 2022-06-17 14:07:16 +08:00
as2252258 e4bf6f22be modify plugin name 2022-06-17 14:04:23 +08:00
as2252258 6c721e957b modify plugin name 2022-06-17 13:54:11 +08:00
as2252258 e224d2e46b modify plugin name 2022-06-17 12:17:23 +08:00
as2252258 ad140bbc00 modify plugin name 2022-06-17 12:05:37 +08:00
as2252258 1f2475b09a modify plugin name 2022-06-17 11:59:19 +08:00
as2252258 41ae0c6118 modify plugin name 2022-06-16 17:38:22 +08:00
as2252258 7d5aec2716 modify plugin name 2022-06-09 10:40:43 +08:00
as2252258 d9b9b78128 modify plugin name 2022-06-09 10:05:37 +08:00
as2252258 9a93687c53 modify plugin name 2022-06-09 10:03:14 +08:00
as2252258 5d395bd6f4 modify plugin name 2022-06-09 10:02:57 +08:00
as2252258 92c6b48cb2 modify plugin name 2022-06-08 16:44:45 +08:00
as2252258 2f9e0a9196 modify plugin name 2022-06-08 16:42:16 +08:00
as2252258 62591edf44 modify plugin name 2022-06-08 16:13:16 +08:00
as2252258 eb36a30b26 modify plugin name 2022-06-08 15:13:53 +08:00
as2252258 a5dde8a140 modify plugin name 2022-06-08 15:13:02 +08:00
as2252258 ba6d854035 modify plugin name 2022-06-08 14:44:55 +08:00
as2252258 9ce43895b1 modify plugin name 2022-06-08 14:43:23 +08:00
as2252258 b8542f6a70 modify plugin name 2022-06-08 14:14:17 +08:00
as2252258 c829192e9c modify plugin name 2022-06-08 14:08:31 +08:00
as2252258 56a20d0f90 变更 2022-05-30 16:55:42 +08:00
as2252258 01d58b4896 变更 2022-05-30 16:55:15 +08:00
as2252258 6046f112f9 变更 2022-05-30 16:54:57 +08:00
as2252258 5670dca21a 变更 2022-05-29 01:52:10 +08:00
as2252258 63d58218e4 modify mysql result 2022-04-28 03:24:58 +08:00
as2252258 2ace780fcb modify mysql result 2022-04-28 03:22:53 +08:00
as2252258 7ea0bee73f modify mysql result 2022-04-28 03:15:44 +08:00
as2252258 6e7955f1d9 modify mysql result 2022-04-10 14:15:39 +08:00
as2252258 cb377b4e69 modify mysql result 2022-04-08 19:19:50 +08:00
as2252258 d4cf6da9fe modify mysql result 2022-04-08 19:18:02 +08:00
as2252258 2057f2ef53 modify plugin name 2022-03-03 18:30:59 +08:00
as2252258 be3106394f modify plugin name 2022-03-01 17:39:54 +08:00
as2252258 cbcad9e7c3 modify plugin name 2022-03-01 17:37:45 +08:00
as2252258 cdec00038c modify plugin name 2022-03-01 17:32:45 +08:00
as2252258 963c495a4d modify plugin name 2022-03-01 17:23:26 +08:00
as2252258 9d23efaed8 modify plugin name 2022-03-01 17:17:23 +08:00
as2252258 918374f1b2 modify plugin name 2022-03-01 17:16:53 +08:00
as2252258 1c7e0814b8 modify plugin name 2022-03-01 16:55:26 +08:00
as2252258 ae135e3538 modify plugin name 2022-03-01 16:51:54 +08:00
as2252258 9fe4c7fd50 modify plugin name 2022-02-28 14:40:13 +08:00
as2252258 ceb8e10d1c modify plugin name 2022-02-27 15:35:31 +08:00
as2252258 036a722753 modify plugin name 2022-02-27 15:31:55 +08:00
as2252258 500f4904f9 modify plugin name 2022-02-27 15:31:21 +08:00
as2252258 9e94626ca5 modify plugin name 2022-02-27 15:29:23 +08:00
as2252258 d4998d4ffc modify plugin name 2022-02-27 10:48:48 +08:00
as2252258 42b2715cf5 modify plugin name 2022-02-27 10:31:35 +08:00
as2252258 df4165ce52 modify plugin name 2022-02-25 19:00:32 +08:00
as2252258 34ae502806 modify plugin name 2022-02-25 18:54:26 +08:00
as2252258 de52786503 modify plugin name 2022-02-25 18:47:45 +08:00
as2252258 0900304c17 modify plugin name 2022-02-25 18:40:41 +08:00
as2252258 521bb2ee7f modify plugin name 2022-02-25 18:37:49 +08:00
as2252258 d6dce71c6c modify plugin name 2022-02-25 18:32:20 +08:00
as2252258 a78760cc3e modify plugin name 2022-02-25 18:23:49 +08:00
as2252258 1e27d52857 modify plugin name 2022-02-25 18:21:57 +08:00
as2252258 1c24908d23 modify plugin name 2022-02-25 18:18:43 +08:00
as2252258 1d809efda8 modify plugin name 2022-02-25 18:16:50 +08:00
as2252258 6febf0c20f modify plugin name 2022-02-25 18:11:09 +08:00
as2252258 eff6ae0e95 modify plugin name 2022-02-25 18:06:04 +08:00
as2252258 dd6424b4ba modify plugin name 2022-02-25 18:05:46 +08:00
as2252258 093d316605 modify plugin name 2022-02-25 18:05:27 +08:00
as2252258 80620e181b modify plugin name 2022-02-25 16:25:32 +08:00
as2252258 1079cab985 modify plugin name 2022-02-25 15:57:40 +08:00
as2252258 a8a2a1fbeb modify plugin name 2022-02-25 15:57:05 +08:00
as2252258 6b3953311a modify plugin name 2022-02-25 15:39:08 +08:00
as2252258 4aff922c83 modify plugin name 2022-02-24 15:24:28 +08:00
as2252258 453481abdb modify plugin name 2022-02-24 11:34:53 +08:00
as2252258 69dbc1e7f3 modify plugin name 2022-02-24 11:00:00 +08:00
as2252258 55f665e10b modify plugin name 2022-02-23 18:02:28 +08:00
as2252258 f54f6fbde3 modify plugin name 2022-02-23 17:24:33 +08:00
as2252258 1ace36b6f6 modify plugin name 2022-02-23 17:08:35 +08:00
as2252258 49d8f03cd0 modify plugin name 2022-02-23 17:07:24 +08:00
as2252258 f5fd9401dd modify plugin name 2022-02-23 16:32:08 +08:00
as2252258 71c95a824c modify plugin name 2022-02-23 11:17:50 +08:00
as2252258 5e0e76fa57 modify plugin name 2022-02-23 11:16:19 +08:00
as2252258 89b4e57726 modify plugin name 2022-02-23 11:13:18 +08:00
as2252258 29c6478169 modify plugin name 2022-02-23 11:08:35 +08:00
as2252258 ecb63ff136 modify plugin name 2022-02-23 11:01:19 +08:00
as2252258 17316250a9 modify plugin name 2022-02-21 10:56:37 +08:00
as2252258 50b6d79756 modify plugin name 2022-02-21 10:52:24 +08:00
as2252258 9626e061b8 modify plugin name 2022-02-21 10:48:43 +08:00
as2252258 3d12b2ea6a modify plugin name 2022-02-18 17:53:05 +08:00
as2252258 ad02cbba65 modify plugin name 2022-02-18 17:27:24 +08:00
as2252258 0278a4aac2 modify plugin name 2022-02-18 15:28:29 +08:00
as2252258 0bd7139232 modify plugin name 2022-02-18 15:16:40 +08:00
as2252258 389ad887e6 modify plugin name 2022-02-18 15:11:44 +08:00
as2252258 576f97a53d modify plugin name 2022-02-18 14:54:54 +08:00
as2252258 42bea9d93a modify plugin name 2022-02-18 14:45:58 +08:00
as2252258 0163758d8e modify plugin name 2022-02-17 18:31:33 +08:00
as2252258 450569fce7 modify plugin name 2022-02-17 18:24:15 +08:00
as2252258 83a29b770a modify plugin name 2022-02-17 18:22:24 +08:00
as2252258 2ebdcbd06b modify plugin name 2022-02-14 17:56:53 +08:00
as2252258 5bac6a843d Revert "改名"
This reverts commit fdf58326
2022-02-10 11:46:02 +08:00
as2252258 5aa5d3ea13 Revert "改名"
This reverts commit fdf58326
2022-01-20 19:04:15 +08:00
as2252258 b10ffd832a Revert "改名"
This reverts commit fdf58326
2022-01-19 14:59:46 +08:00
as2252258 d42fc588b4 Revert "改名"
This reverts commit fdf58326
2022-01-19 14:57:14 +08:00
as2252258 d5b58a1fc7 Revert "改名"
This reverts commit fdf58326
2022-01-19 14:32:23 +08:00
as2252258 cada515dc7 Revert "改名"
This reverts commit fdf58326
2022-01-19 11:30:58 +08:00
as2252258 5d73bb2c33 Revert "改名"
This reverts commit fdf58326
2022-01-18 18:55:36 +08:00
as2252258 164065493e Revert "改名"
This reverts commit fdf58326
2022-01-18 18:53:54 +08:00
as2252258 7cf28a3aaa Revert "改名"
This reverts commit fdf58326
2022-01-18 18:07:58 +08:00
as2252258 63a1322025 Revert "改名"
This reverts commit fdf58326
2022-01-18 18:07:35 +08:00
as2252258 e89062a2d7 Revert "改名"
This reverts commit fdf58326
2022-01-18 18:06:24 +08:00
as2252258 bc0fa6b8d5 Revert "改名"
This reverts commit fdf58326
2022-01-18 18:01:44 +08:00
as2252258 ffadbdab83 Revert "改名"
This reverts commit fdf58326
2022-01-18 17:56:47 +08:00
as2252258 267358263a Revert "改名"
This reverts commit fdf58326
2022-01-18 17:55:39 +08:00
as2252258 209621f222 Revert "改名"
This reverts commit fdf58326
2022-01-18 17:53:32 +08:00
as2252258 6e75fa462b Revert "改名"
This reverts commit fdf58326
2022-01-18 17:24:50 +08:00
as2252258 57f9e3254d Revert "改名"
This reverts commit fdf58326
2022-01-17 11:48:11 +08:00
as2252258 22194bbdbc Revert "改名"
This reverts commit fdf58326
2022-01-17 11:31:26 +08:00
as2252258 5b22955966 Revert "改名"
This reverts commit fdf58326
2022-01-14 16:50:01 +08:00
as2252258 ac0c08f909 Revert "改名"
This reverts commit fdf58326
2022-01-14 16:23:15 +08:00
as2252258 c1e480cd43 Revert "改名"
This reverts commit fdf58326
2022-01-14 16:12:20 +08:00
as2252258 61741f926f Revert "改名"
This reverts commit fdf58326
2022-01-14 16:11:23 +08:00
as2252258 f3d878e21c Revert "改名"
This reverts commit fdf58326
2022-01-14 16:07:57 +08:00
as2252258 4ca0a61344 Revert "改名"
This reverts commit fdf58326
2022-01-14 16:06:31 +08:00
as2252258 6d699df26e Revert "改名"
This reverts commit fdf58326
2022-01-14 16:05:11 +08:00
as2252258 22e094804a Revert "改名"
This reverts commit fdf58326
2022-01-14 16:03:26 +08:00
as2252258 f8a07c30ae Revert "改名"
This reverts commit fdf58326
2022-01-14 16:03:01 +08:00
as2252258 c735776e58 Revert "改名"
This reverts commit fdf58326
2022-01-14 15:52:38 +08:00
as2252258 c5b4f4795b Revert "改名"
This reverts commit fdf58326
2022-01-14 14:15:34 +08:00
as2252258 661206b94b Revert "改名"
This reverts commit fdf58326
2022-01-14 11:29:15 +08:00
as2252258 61f589058e Revert "改名"
This reverts commit fdf58326
2022-01-13 16:32:44 +08:00
as2252258 6d83f647f4 Revert "改名"
This reverts commit fdf58326
2022-01-12 17:51:00 +08:00
as2252258 870595b810 Revert "改名"
This reverts commit fdf58326
2022-01-12 17:49:02 +08:00
as2252258 970f22804d Revert "改名"
This reverts commit fdf58326
2022-01-12 17:48:48 +08:00
as2252258 dad6a63ee2 Revert "改名"
This reverts commit fdf58326
2022-01-12 14:10:32 +08:00
as2252258 47ed967e46 Revert "改名"
This reverts commit fdf58326
2022-01-11 10:51:50 +08:00
51 changed files with 4674 additions and 5926 deletions
+121 -232
View File
@@ -9,332 +9,221 @@ declare(strict_types=1);
namespace Database;
use Closure;
use Database\Traits\QueryTrait;
use Exception;
use JetBrains\PhpStorm\ArrayShape;
use Kiri\Abstracts\Component;
use Kiri\Di\Context;
use Swoole\Coroutine;
/**
* Class ActiveQuery
* @package Database
*/
class ActiveQuery extends Component implements ISqlBuilder
class ActiveQuery extends QueryTrait implements ISqlBuilder
{
use QueryTrait;
/** @var array */
public array $with = [];
public bool $asArray = FALSE;
protected mixed $_mock = null;
/** @var bool */
public bool $asArray = FALSE;
/** @var bool */
public bool $useCache = FALSE;
/**
* @var Connection|null
* @param bool $asArray
* @return static
*/
public ?Connection $db = NULL;
public function asArray(bool $asArray = true): static
{
$this->asArray = $asArray;
return $this;
}
/**
* @var array
* 参数绑定
* @param array $methods
* @return $this
*/
public array $attributes = [];
public function with(array $methods): static
{
$this->modelClass->setWith($methods);
return $this;
}
/**
* Comply constructor.
* @param $model
* @param array $config
* @return ModelInterface|array|null|bool
* @throws
*/
public function __construct($model, array $config = [])
public function first(): ModelInterface|null|array|bool
{
$this->modelClass = $model;
$data = $this->buildCommand($this->builder->one())->one();
if (is_array($data)) {
return $this->populate($data);
}
return null;
}
$this->builder = SqlBuilder::builder($this);
parent::__construct($config);
/**
* @return bool|Collection
*/
public function get(): bool|Collection
{
$data = $this->buildCommand($this->builder->all())->all();
if (is_array($data)) {
return new Collection($this, $this->modelClass, $data);
}
return false;
}
/**
* 清除不完整数据
* @throws
*/
public function clear()
public function flush(): bool
{
$this->db = NULL;
$this->useCache = FALSE;
$this->with = [];
}
/**
* @param $key
* @param $value
* @return $this
*/
public function addParam($key, $value): static
{
$this->attributes[$key] = $value;
return $this;
return (bool)$this->buildCommand($this->builder->truncate())->exec();
}
/**
* @param int $size
* @param int $page
* @return array
* @throws Exception
* @param Closure $closure
* @return void
*/
#[ArrayShape(['code' => "int", 'message' => "string", 'size' => "mixed", 'page' => "mixed", 'count' => "int", 'next' => "mixed", 'prev' => "mixed", 'param' => "array"])]
public function pagination(int $size = 20, int $page = 1): array
public function chunk(int $size, Closure $closure): void
{
$page = max(1, $page);
$size = max(1, $size);
$offset = ($page - 1) * $size;
$count = $this->count();
$lists = $this->limit($offset, $size)->get()->toArray();
return [
'code' => 0,
'message' => 'ok',
'size' => $size,
'page' => $page,
'count' => $count,
'next' => max($page + 1, 1),
'prev' => max($page - 1, 1),
'param' => $lists,
];
}
/**
* @param array $values
* @return $this
*/
public function addParams(array $values): static
{
foreach ($values as $key => $val) {
$this->addParam($key, $val);
if ($this->offset === -1) $this->offset = 0;
$data = $this->offset($this->offset)->limit($size)->get();
if (!$data || $data->isEmpty()) {
return;
}
return $this;
}
/**
* @param $name
* @return $this
*/
public function with($name): static
{
if (empty($name)) {
return $this;
if (Context::inCoroutine()) {
Coroutine::create(fn() => $closure($data));
} else {
call_user_func($closure, $data);
}
if (is_string($name)) {
$name = explode(',', $name);
}
foreach ($name as $val) {
array_push($this->with, $val);
}
return $this;
}
/**
* @param $sql
* @param array $params
* @return mixed
* @throws Exception
*/
public function execute($sql, array $params = []): Command
{
return $this->modelClass->getConnection()->createCommand($sql, $params);
}
/**
* @return ModelInterface|null
* @throws Exception
*/
public function first(): ModelInterface|null
{
$data = $this->execute($this->builder->one())->one();
if (empty($data)) {
return NULL;
}
return $this->populate($data);
}
/**
* @return string
* @throws Exception
*/
public function toSql(): string
{
return $this->builder->get();
}
/**
* @return array|Collection
*/
public function get(): Collection|array
{
return $this->all();
}
/**
* @throws Exception
*/
public function flush(): array|bool|int|string|null
{
return $this->execute($this->builder->truncate())->exec();
}
/**
* @param int $size
* @param callable $callback
* @return Pagination
* @throws Exception
*/
public function page(int $size, callable $callback): Pagination
{
$pagination = new Pagination($this);
$pagination->setOffset(0);
$pagination->setLimit($size);
$pagination->setCallback($callback);
return $pagination;
$this->offset += $size;
$this->chunk($size, $closure);
}
/**
* @param string $field
* @param string $setKey
* @param string|null $setKey
*
* @return array|null
* @throws Exception
*/
public function column(string $field, string $setKey = ''): ?array
public function column(string $field, ?string $setKey = null): ?array
{
return $this->all()->column($field, $setKey);
}
/**
* @return array|Collection
* @throws
*/
public function all(): Collection|array
{
$data = $this->execute($this->builder->all())->all();
if (!empty($this->with)) {
$this->getWith($this->modelClass);
}
$collect = new Collection($this, $data, $this->modelClass);
if ($this->asArray) {
return $collect->toArray();
}
return $collect;
}
/**
* @param $data
* @return ModelInterface
* @throws Exception
*/
public function populate($data): ModelInterface
{
return $this->getWith($this->modelClass::populate($data));
return $this->get()->column($field, $setKey);
}
/**
* @param ModelInterface $model
* @return ModelInterface
* @param mixed $value
* @return $this
*/
public function getWith(ModelInterface $model): ModelInterface
public function withMock(mixed $value): static
{
if (empty($this->with) || !is_array($this->with)) {
return $model;
}
return $model->setWith($this->with);
$this->_mock = $value;
return $this;
}
/**
* @return int
* @throws Exception
* @return mixed
*/
public function count(): int
public function mock(): mixed
{
$data = $this->execute($this->builder->count())->one();
if ($data && is_array($data)) {
return (int)array_shift($data);
}
return 0;
return $this->_mock;
}
/**
* @param array $data
* @return array|Command|bool|int|string
* @throws Exception
* @return ModelInterface|array
* @throws
*/
public function batchUpdate(array $data): Command|array|bool|int|string
public function populate(array $data): ModelInterface|array
{
$model = $this->modelClass->populates($data);
return $this->asArray ? $model->toArray() : $model;
}
/**
* @return int
* @throws
*/
public function count(): int
{
return $this->buildCommand($this->builder->count())->rowCount();
}
/**
* @param array $data
* @return bool
* @throws
*/
public function update(array $data): bool
{
if (count($data) < 1) {
return true;
}
$generate = $this->builder->update($data);
if (is_bool($generate)) {
if (!is_bool($generate)) {
return (bool)$this->buildCommand($generate)->exec();
} else {
return $generate;
}
return $this->execute(...$generate)->exec();
}
/**
* @param array $data
* @return bool
* @throws Exception
*/
public function batchInsert(array $data): bool
public function insert(array $data): bool
{
[$sql, $params] = $this->builder->insert($data, TRUE);
$sql = $this->builder->insert($data, isset($data[0]));
return $this->execute($sql, $params)->exec();
return (bool)$this->buildCommand($sql)->exec();
}
/**
* @param $filed
* @param string $filed
*
* @return null
* @throws Exception
* @return mixed
* @throws
*/
public function value($filed)
public function value(string $filed): mixed
{
return $this->first()[$filed] ?? NULL;
}
/**
* @return bool
* @throws Exception
* @throws
*/
public function exists(): bool
{
return !empty($this->execute($this->builder->one())->fetchColumn());
return $this->buildCommand($this->limit(1)->builder->exists())->exists();
}
/**
* @param bool $getSql
* @return int|bool|string|null
* @throws Exception
* @param string $sql
* @param array $params
* @return int|bool
*/
public function delete(bool $getSql = FALSE): int|bool|string|null
public function execute(string $sql, array $params = []): int|bool
{
$sql = $this->builder->delete();
if ($getSql === FALSE) {
return $this->execute($sql)->delete();
}
return $sql;
return $this->buildCommand($sql, $params)->exec();
}
/**
* @return bool
*/
public function delete(): bool
{
return $this->buildCommand($this->builder->delete())->delete();
}
}
-2
View File
@@ -2,8 +2,6 @@
namespace Database\Affair;
use Exception;
class Commit
{
-44
View File
@@ -1,44 +0,0 @@
<?php
namespace Database\Annotation;
use Attribute;
use Database\Base\Getter;
use Exception;
/**
* Class Get
* @package Annotation\Model
*/
#[Attribute(Attribute::TARGET_METHOD)] class Get extends \Annotation\Attribute
{
/**
* Get constructor.
* @param string $name
*/
public function __construct(public string $name)
{
}
/**
* @param static $params
* @param mixed $class
* @param mixed|null $method
* @return bool
* @throws \Kiri\Exception\NotFindClassException
* @throws \ReflectionException
*/
public function execute(mixed $class, mixed $method = null): bool
{
di(Getter::class)->addGetter($this->name, $class, $method);
return true;
}
}
-41
View File
@@ -1,41 +0,0 @@
<?php
namespace Database\Annotation;
use Kiri\Annotation\Attribute;
use Database\Base\Relate;
use Exception;
/**
* Class Relation
* @package Annotation\Model
*/
#[\Attribute(\Attribute::TARGET_METHOD)] class Relation extends Attribute
{
/**
* Relation constructor.
* @param string $name
*/
public function __construct(public string $name)
{
}
/**
* @param mixed $class
* @param mixed|null $method
* @return bool
* @throws Exception
*/
public function execute(mixed $class, mixed $method = null): bool
{
di(Relate::class)->addRelate($this->name, $class, $method);
return true;
}
}
-39
View File
@@ -1,39 +0,0 @@
<?php
namespace Database\Annotation;
use Kiri\Annotation\Attribute;
use Database\Base\Setter;
use Exception;
#[\Attribute(\Attribute::TARGET_METHOD)] class Set extends Attribute
{
/**
* Set constructor.
* @param string $name
*/
public function __construct(public string $name)
{
}
/**
* @param static $params
* @param mixed $class
* @param mixed|null $method
* @return bool
* @throws \Kiri\Exception\NotFindClassException
* @throws \ReflectionException
*/
public function execute(mixed $class, mixed $method = null): bool
{
di(Setter::class)->addSetter($this->name, $class, $method);
return true;
}
}
+288
View File
@@ -0,0 +1,288 @@
<?php
declare(strict_types=1);
namespace Database;
use Co\Channel;
use Exception;
use Swoole\Coroutine;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
*
*/
class BackupCommand extends Command
{
public string $command = 'db:backup';
public string $description = 'php kiri.php db:backup --database users --table u_user --data 1 /Users/admin/snowflake-bi/test.sql';
public array $percentStatus = [];
/**
*
*/
protected function configure()
{
$this->setName('db:backup')
->addOption('data', 'd', InputArgument::OPTIONAL)
->addArgument('path', InputArgument::REQUIRED, "save to path", null)
->addOption('table', 't', InputArgument::OPTIONAL)
->addOption('database', 'db', InputArgument::OPTIONAL)
->setDescription('php kiri.php db:backup --database users --table u_user --data 1 /Users/admin/snowflake-bi/test.sql');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
* @throws Exception
*/
public function execute(InputInterface $input, OutputInterface $output): int
{
try {
/** @var Connection $data */
$data = \Kiri::getDi()->get(DatabasesProviders::class)->get($input->getOption('database'));
$table = $input->getOption('table');
if ($table !== null) {
$table = explode(',', $table);
} else {
$tmp = $data->createCommand('show tables from `' . $data->database . '`')->all();
$table = [];
foreach ($tmp as $value) {
$table[] = current($value);
}
}
$path = $input->getArgument('path');
if (!str_starts_with($path, '/')) {
$path = APP_PATH . $path;
}
$isData = $input->getOption('data');
if (!is_dir($path)) {
mkdir($path);
}
$waite = new Coroutine\WaitGroup();
foreach ($table as $value) {
$tableInfo = $data->createCommand('show create table `' . $data->database . '`.`' . $value . '`')->one();
$tmp = rtrim($path, '/') . '/' . current($tableInfo) . '.sql';
if (!file_exists($tmp)) {
touch($tmp);
}
file_put_contents($tmp, '');
$tableCreator = next($tableInfo);
if (preg_match('/AUTO_INCREMENT=\d+\s/', $tableCreator)) {
$tableCreator = preg_replace('/AUTO_INCREMENT=\d+\s/', 'AUTO_INCREMENT=1 ', $tableCreator);
}
file_put_contents($tmp, $tableCreator . ';' . PHP_EOL . PHP_EOL, FILE_APPEND);
if ($isData == 1) {
$waite->add(1);
Coroutine::create(function () use ($waite, $input, $value, $tmp) {
defer(function () use ($waite) {
$waite->done();
});
$this->writeData($input->getOption('database'), $value, $tmp);
});
}
}
$waite->wait();
$output->write('dump data success');
} catch (\Throwable $throwable) {
$output->writeln(throwable($throwable));
} finally {
return 1;
}
}
public bool $isEnd = false;
/**
* @param string $dbname
* @param string $tableName
* @param string $path
* @return void
* @throws Exception
*/
public function writeData(string $dbname, string $tableName, string $path): void
{
$offset = 0;
$size = 1000;
$channel = new Channel(200);
for ($i = 0; $i < 200; $i++) {
Coroutine::create(function () use ($channel, $path, $dbname, $tableName) {
while ($channel->errCode != SWOOLE_CHANNEL_CLOSED) {
if (($data = $channel->pop()) === false) {
break;
}
if (($value = json_decode($data, true)) === null) {
continue;
}
$value = $this->toSql($dbname, $tableName, $value);
file_put_contents($path, $value . PHP_EOL, FILE_APPEND);
}
});
}
$id = Coroutine::create(function () use ($channel) {
$data = Coroutine::waitSignal(SIGTERM | SIGINT);
if ($data) {
$this->isEnd = true;
}
});
/** @var Connection $database */
$database = \Kiri::getDi()->get(DatabasesProviders::class)->get($dbname);
$total = $database->createCommand("SELECT COUNT(*) as total FROM " . $tableName)->one()['total'];
$startTime = time();
$wait = new Coroutine\WaitGroup();
while ($this->isEnd === false && $offset < $total) {
$wait->add(1);
Coroutine::create(function () use ($wait, $offset, $size, $total, $dbname, $tableName, $channel) {
defer(function () use ($wait) {
$wait->done();
});
/** @var Connection $database */
$database = \Kiri::getDi()->get(DatabasesProviders::class)->get($dbname);
$data = $database->createCommand("SELECT * FROM $tableName LIMIT $offset,$size")->all();
if (is_bool($data) || count($data) < 1) {
return;
}
$channel->push(json_encode($data));
$this->percentStatus[$dbname . $tableName] = intval(round(($offset + $size) / $total, 2) * 100);
$this->outputProgress(true);
});
$offset += $size;
}
$wait->wait();
echo 'use time ' . (time() - $startTime) . 's' . PHP_EOL;
$channel->close();
Coroutine::cancel($id);
}
/**
* @param string $dbname
* @param string $value
* @param array $data
* @return string
*/
public function toSql(string $dbname, string $value, array $data): string
{
$strings = ['INSERT INTO ' . $dbname . '.' . $value, '(' . implode(',', array_keys($data[0])) . ') VALUES'];
foreach ($data as $datum) {
$keys = array_values($datum);
$encode = [];
foreach ($keys as $val) {
if (is_string($val)) {
$encode[] = '\'' . addcslashes($val, "\\'") . '\'';
} else {
$encode[] = $val === '' ? '\'\'' : $val;
}
}
$strings[] = '(' . implode(',', $encode) . '),';
}
return rtrim(implode('', $strings), ',') . ';';
}
/**
* @param $key
* @param $percent
* @return string
* 组合成进度条
*/
public function buildLine($key, $percent): string
{
$repeatTimes = 100;
if ($percent > 100) $percent = 100;
if ($percent > 0) {
$hasColor = str_repeat('■', $percent);
} else {
$hasColor = '';
}
if ($repeatTimes - $percent > 0) {
$noColor = str_repeat(' ', $repeatTimes - $percent);
} else {
$noColor = '';
}
if ($percent !== 100) {
$percentString = sprintf("[ %s %-6s]", $key, $percent . '%');
} else {
$percentString = sprintf("[ %s %-5s]", $key, 'OK');;
}
return $percentString . "[{$hasColor}{$noColor}]" . "\r";
}
/**
* @param bool $clear
* @return void
* 输出进度条
*/
public function outputProgress(bool $clear = false): void
{
if ($clear) {
$number = count($this->percentStatus);
for ($i = 0; $i < $number; $i++) {
system("tput cuu1");
system("tput el");
}
}
foreach ($this->percentStatus as $key => $value) {
echo $this->buildLine($key, $value) . "\n";
}
}
/**
* @param $k
* @param $value
* @return void
* 更新进度条值
*/
public function updateProgressValue($k, $value): void
{
$this->percentStatus[$k] = $value;
if ($this->percentStatus[$k] >= 1000) {
$this->percentStatus[$k] = 1000;
$this->outputProgress(true);
return;
}
$this->outputProgress(true);
usleep(50000);
}
}
+36 -31
View File
@@ -13,8 +13,6 @@ namespace Database\Base;
use ArrayIterator;
use Database\ActiveQuery;
use Database\ModelInterface;
use Kiri\ToArray;
use Exception;
use JetBrains\PhpStorm\Pure;
use Kiri\Abstracts\Component;
use ReturnTypeWillChange;
@@ -24,40 +22,36 @@ use Traversable;
* Class AbstractCollection
* @package Database\Base
*/
abstract class AbstractCollection extends Component implements \IteratorAggregate, \ArrayAccess, ToArray
abstract class AbstractCollection extends Component implements \IteratorAggregate, \ArrayAccess, \Arrayable
{
/**
* @var ModelInterface[]
*/
protected array $_item = [];
protected ModelInterface|string|null $model;
protected ActiveQuery $query;
private array $_item;
public function clean()
/**
* @return array
*/
public function getItems(): array
{
unset($this->query, $this->model, $this->_item);
// TODO: Change the autogenerated stub
return $this->_item;
}
/**
* Collection constructor.
*
* @param $query
* @param array $array
* @param ModelInterface|null $model
* @throws Exception
*/
public function __construct($query, array $array = [], ModelInterface $model = null)
/**
* Collection constructor.
*
* @param ActiveQuery $query
* @param array $array
* @param ModelInterface|null $model
*/
public function __construct(public ActiveQuery $query, public ?ModelInterface $model = null, array $array = [])
{
$this->_item = $array;
$this->query = $query;
$this->model = $model;
parent::__construct([]);
parent::__construct();
}
@@ -73,7 +67,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
/**
* @param $item
*/
public function setItems($item)
public function setItems($item): void
{
$this->_item = $item;
}
@@ -82,7 +76,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
/**
* @param $model
*/
public function setModel($model)
public function setModel($model): void
{
$this->model = $model;
}
@@ -90,14 +84,14 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
/**
* @param $item
*/
public function addItem($item)
public function addItem($item): void
{
$this->_item[] = $item;
}
/**
* @return Traversable|CollectionIterator|ArrayIterator
* @throws Exception
* @throws
*/
public function getIterator(): Traversable|CollectionIterator|ArrayIterator
{
@@ -107,7 +101,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
/**
* @return mixed
* @throws Exception
* @throws
*/
public function getModel(): ModelInterface
{
@@ -115,6 +109,15 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
}
/**
* @return ActiveQuery
*/
public function makeNewQuery(): ActiveQuery
{
return $this->model::query();
}
/**
* @param mixed $offset
* @return bool
@@ -127,7 +130,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
/**
* @param mixed $offset
* @return ModelInterface|null
* @throws Exception
* @throws
*/
public function offsetGet(mixed $offset): ?ModelInterface
{
@@ -144,7 +147,8 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
* @param mixed $offset
* @param mixed $value
*/
#[ReturnTypeWillChange] public function offsetSet(mixed $offset, mixed $value)
#[ReturnTypeWillChange]
public function offsetSet(mixed $offset, mixed $value): void
{
$this->_item[$offset] = $value;
}
@@ -153,7 +157,8 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
/**
* @param mixed $offset
*/
#[ReturnTypeWillChange] public function offsetUnset(mixed $offset)
#[ReturnTypeWillChange]
public function offsetUnset(mixed $offset): void
{
if ($this->offsetExists($offset)) {
unset($this->_item[$offset]);
+270
View File
@@ -0,0 +1,270 @@
<?php
namespace Database\Base;
use Closure;
use Database\Collection;
use Database\Traits\QueryTrait;
interface ActiveQueryInterface
{
/**
* @param string $column
* @param callable $callable
* @return QueryTrait
*/
public function when(string $column, callable $callable): QueryTrait;
/**
* @param string $whereRaw
* @return QueryTrait
*/
public function whereRaw(string $whereRaw): QueryTrait;
/**
* @param string $column
* @param string $value
* @return QueryTrait
*/
public function whereLocate(string $column, string $value): QueryTrait;
/**
* @param string $column
* @return QueryTrait
*/
public function whereNull(string $column): QueryTrait;
/**
* @param string $column
* @return QueryTrait
*/
public function whereEmpty(string $column): QueryTrait;
/**
* @param string $column
* @return QueryTrait
*/
public function whereNotEmpty(string $column): QueryTrait;
/**
* @param string $column
* @return QueryTrait
*/
public function whereNotNull(string $column): QueryTrait;
/**
* @param string $alias
*
* @return QueryTrait select * from tableName as t1
*
* select * from tableName as t1
*/
public function alias(string $alias = 't1'): QueryTrait;
/**
* @param string|Closure $tableName
*
* @return QueryTrait
*/
public function from(string|Closure $tableName): QueryTrait;
/**
* @param string $tableName
* @param string $alias
* @param array $onCondition
* @param array $param
* @return QueryTrait
*/
public function leftJoin(string $tableName, string $alias, array $onCondition, array $param = []): QueryTrait;
/**
* @param string $tableName
* @param string $alias
* @param array $onCondition
* @param array $param
* @return QueryTrait
*/
public function rightJoin(string $tableName, string $alias, array $onCondition, array $param = []): QueryTrait;
/**
* @param string $tableName
* @param string $alias
* @param array $onCondition
* @param array $param
* @return QueryTrait
*/
public function innerJoin(string $tableName, string $alias, array $onCondition, array $param = []): QueryTrait;
/**
* @param string $field
*
* @return QueryTrait
*/
public function sum(string $field): QueryTrait;
/**
* @param string $field
* @return QueryTrait
*/
public function max(string $field): QueryTrait;
/**
* @param string $lngField
* @param string $latField
* @param int|float $lng1
* @param int|float $lat1
*
* @return QueryTrait
*/
public function distance(string $lngField, string $latField, int|float $lng1, int|float $lat1): QueryTrait;
/**
* @param string|array $column
* @param string $sort
*
* @return QueryTrait [
*
* [
* 'addTime',
* 'descTime desc'
* ]
*/
public function orderBy(string|array $column, string $sort = 'DESC'): QueryTrait;
/**
* @param array $column
*
* @return QueryTrait
*/
public function select(array $column = ['*']): QueryTrait;
/**
* @return QueryTrait
*/
public function rand(): QueryTrait;
/**
* @param array|Closure|string $conditionArray
* @param string $opera
* @param null $value
* @return QueryTrait
*/
public function whereOr(array|Closure|string $conditionArray = [], string $opera = '=', $value = null): QueryTrait;
/**
* @param string $column
* @param string $value
* @return QueryTrait
*/
public function whereLike(string $column, string $value): QueryTrait;
/**
* @param string $column
* @param string $value
* @return QueryTrait
*/
public function whereLeftLike(string $column, string $value): QueryTrait;
/**
* @param string $column
* @param string $value
* @return QueryTrait
*/
public function whereRightLike(string $column, string $value): QueryTrait;
/**
* @param string $column
* @param string $value
* @return QueryTrait
*/
public function whereNotLike(string $column, string $value): QueryTrait;
/**
* @param string $columns
* @param array|Closure $value
* @return QueryTrait
*/
public function whereIn(string $columns, array|Closure $value): QueryTrait;
/**
* @param string $columns
* @param array $value
* @return QueryTrait
*/
public function whereNotIn(string $columns, array $value): QueryTrait;
/**
* @param string $column
* @param int|float $start
* @param int|float $end
* @return QueryTrait
*/
public function whereBetween(string $column, int|float $start, int|float $end): QueryTrait;
/**
* @param string $column
* @param int|float $start
* @param int|float $end
* @return QueryTrait
*/
public function whereNotBetween(string $column, int|float $start, int|float $end): QueryTrait;
/**
* @param array|string $column
* @param mixed|null $value
* @return QueryTrait
*/
public function where(array|string $column, mixed $value = null): QueryTrait;
/**
* @param string $column
* @param string $opera
* @param mixed $value
* @return QueryTrait
*/
public function whereMath(string $column, string $opera, mixed $value): QueryTrait;
/**
* @param Closure $closure
* @return QueryTrait
*/
public function whereClosure(Closure $closure): QueryTrait;
/**
* @param string $name
* @param string|null $having
*
* @return QueryTrait
*/
public function groupBy(string $name, string $having = NULL): QueryTrait;
/**
* @param int $limit
*
* @return QueryTrait
*/
public function limit(int $limit = 20): QueryTrait;
/**
* @param int $offset
* @return QueryTrait
*/
public function offset(int $offset): QueryTrait;
}
+36 -35
View File
@@ -5,9 +5,7 @@ declare(strict_types=1);
namespace Database\Base;
use Database\ActiveQuery;
use Database\ModelInterface;
use Exception;
/**
@@ -17,45 +15,48 @@ use Exception;
class CollectionIterator extends \ArrayIterator
{
private ModelInterface|string $model;
/**
* @var ModelInterface|string
*/
private ModelInterface|string $model;
/**
* CollectionIterator constructor.
* @param $model
* @param array $array
* @param int $flags
* @throws Exception
*/
public function __construct($model, array $array = [], int $flags = 0)
{
$this->model = $model;
parent::__construct($array, $flags);
}
/**
* CollectionIterator constructor.
* @param $model
* @param array $array
* @param int $flags
* @throws
*/
public function __construct($model, array $array = [], int $flags = 0)
{
$this->model = $model;
parent::__construct($array, $flags);
}
/**
* @param $current
* @return ModelInterface
* @throws Exception
*/
protected function newModel($current): ModelInterface
{
return $this->model->populates($current);
}
/**
* @param $current
* @return ModelInterface
* @throws
*/
protected function newModel($current): ModelInterface
{
return $this->model->populates($current);
}
/**
* @throws Exception
*/
public function current(): ModelInterface
{
if (is_array($current = parent::current())) {
$current = $this->newModel($current);
}
return $current;
}
/**
* @throws
*/
public function current(): ModelInterface
{
if (is_array($current = parent::current())) {
$current = $this->newModel($current);
}
return $current;
}
}
-71
View File
@@ -1,71 +0,0 @@
<?php
declare(strict_types=1);
namespace Database\Base;
use Database\Condition\BetweenCondition;
use Database\Condition\InCondition;
use Database\Condition\LikeCondition;
use Database\Condition\LLikeCondition;
use Database\Condition\MathematicsCondition;
use Database\Condition\NotBetweenCondition;
use Database\Condition\NotInCondition;
use Database\Condition\NotLikeCondition;
use Database\Condition\RLikeCondition;
/**
* Class ConditionClassMap
* @package Database\Base
*/
class ConditionClassMap
{
public static array $conditionMap = [
'IN' => [
'class' => InCondition::class
],
'NOT IN' => [
'class' => NotInCondition::class
],
'LIKE' => [
'class' => LikeCondition::class
],
'NOT LIKE' => [
'class' => NotLikeCondition::class
],
'LLike' => [
'class' => LLikeCondition::class
],
'RLike' => [
'class' => RLikeCondition::class
],
'EQ' => [
'class' => MathematicsCondition::class,
'type' => 'EQ'
],
'NEQ' => [
'class' => MathematicsCondition::class,
'type' => 'NEQ'
],
'GT' => [
'class' => MathematicsCondition::class,
'type' => 'GT'
],
'EGT' => [
'class' => MathematicsCondition::class,
'type' => 'EGT'
],
'LT' => [
'class' => MathematicsCondition::class,
'type' => 'LT'
],
'ELT' => [
'class' => MathematicsCondition::class,
'type' => 'ELT'
],
'BETWEEN' => BetweenCondition::class,
'NOT BETWEEN' => NotBetweenCondition::class,
];
}
-35
View File
@@ -1,35 +0,0 @@
<?php
namespace Database\Base;
class Getter
{
private array $_classMapping = [];
/**
* @param $name
* @param $class
* @param $method
*/
public function addGetter($name, $class, $method)
{
$this->_classMapping[$class][$name] = $method;
}
/**
* @param $class
* @param null $name
* @return array|string|null
*/
public function getGetter($class, $name = null): null|array|string
{
if (!empty($name)) {
return $this->_classMapping[$class][$name] ?? null;
}
return $this->_classMapping[$class] ?? [];
}
}
+793 -1050
View File
File diff suppressed because it is too large Load Diff
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace Database\Base;
class PDO extends \PDO
{
/**
* @param string $database
* @param string $host
* @param string $username
* @param string $password
* @param array $options
*/
public function __construct(
readonly public string $database,
readonly public string $host,
readonly public string $username,
readonly public string $password,
readonly public array $options,
)
{
parent::__construct('mysql:dbname=' . $this->database . ';host=' . $this->host, $this->username, $this->password, $this->options);
}
}
-36
View File
@@ -1,36 +0,0 @@
<?php
namespace Database\Base;
class Relate
{
private array $_classMapping = [];
/**
* @param $name
* @param $class
* @param $method
*/
public function addRelate($name, $class, $method)
{
$this->_classMapping[$class][$name] = $method;
}
/**
* @param $class
* @param $name
* @return null|array|string
*/
public function getRelate($class, $name = null): null|array|string
{
if (!empty($name)) {
return $this->_classMapping[$class][$name] ?? null;
}
return $this->_classMapping[$class] ?? [];
}
}
-32
View File
@@ -1,32 +0,0 @@
<?php
namespace Database\Base;
class Setter
{
private array $_classMapping = [];
/**
* @param $name
* @param $class
* @param $method
*/
public function addSetter($name, $class, $method)
{
$this->_classMapping[$class][$name] = $method;
}
/**
* @param $class
* @param $name
* @return null|array|string
*/
public function getSetter($class, $name): null|array|string
{
return $this->_classMapping[$class][$name] ?? null;
}
}
+204 -213
View File
@@ -21,223 +21,214 @@ use JetBrains\PhpStorm\Pure;
class Collection extends AbstractCollection
{
/**
* @return array
*/
public function getItems(): array
{
// TODO: Change the autogenerated stub
return $this->_item;
}
/**
* @param $field
*
* @return array|null
* @throws Exception
*/
public function values($field): ?array
{
if (empty($field) || !is_string($field)) {
return NULL;
}
$_tmp = [];
$data = $this->toArray();
foreach ($data as $val) {
/** @var ModelInterface $val */
$_tmp[] = $val[$field];
}
return $_tmp;
}
/**
* @param string $field
* @return array|null
*/
public function keyBy(string $field): ?array
{
$array = $this->toArray();
$column = array_flip(array_column($array, $field));
foreach ($column as $key => $value) {
$column[$key] = $array[$value];
}
return $column;
}
/**
* @return $this
*/
public function orderRand(): static
{
shuffle($this->_item);
return $this;
}
/**
* @param int $start
* @param int $length
*
* @return array
*/
#[Pure] public function slice(int $start = 0, int $length = 20): array
{
if (empty($this->_item) || !is_array($this->_item)) {
return [];
}
if (count($this->_item) < $length) {
return $this->_item;
} else {
return array_slice($this->_item, $start, $length);
}
}
/**
* @param string $field
* @param string $setKey
*
* @return array|null
*/
public function column(string $field, string $setKey = ''): ?array
{
$data = $this->toArray();
if (empty($data)) {
return [];
}
if (!empty($setKey) && is_string($setKey)) {
return array_column($data, $field, $setKey);
} else {
return array_column($data, $field);
}
}
/**
* @param string $field
*
* @return float|int|null
*/
public function sum(string $field): float|int|null
{
$array = $this->column($field);
if (empty($array)) {
return NULL;
}
return array_sum($array);
}
/**
* @return ModelInterface|array
*/
#[Pure] public function current(): ModelInterface|array
{
return current($this->_item);
}
/**
* @return int
*/
#[Pure] public function size(): int
{
return (int)count($this->_item);
}
/**
* @return array
* @throws
*/
public function toArray(): array
{
$array = [];
/** @var Model $value */
foreach ($this as $value) {
if (!is_object($value)) {
continue;
}
$array[] = $value->setWith($this->query->with)->toArray();
}
$this->_item = [];
return $array;
}
/**
* @throws Exception
* 批量删除
*/
public function delete(): bool
{
$model = $this->getModel();
if (!$model->hasPrimary()) return false;
$ids = [];
foreach ($this as $item) {
$id = $item->getPrimaryValue();
if (!empty($id)) {
$ids[] = $id;
}
}
return $model::query()->whereIn($model->getPrimary(), $ids)->delete();
}
/**
* @param array $condition
* @return Collection
* @throws
*/
public function filter(array $condition): Collection|static
{
$_filters = [];
if (empty($condition)) {
return $this;
}
foreach ($this as $value) {
if (!$this->filterCheck($value, $condition)) {
continue;
}
$_filters[] = $value;
}
return new Collection($this->query, $_filters, $this->model);
}
/**
* @param string $field
*
* @return array|null
*/
public function values(string $field): ?array
{
return array_values($this->column($field));
}
/**
* @param $value
* @param $condition
* @return bool
* @throws Exception
*/
private function filterCheck($value, $condition): bool
{
$_value = $value;
if ($_value instanceof ModelInterface) {
$_value = $_value->toArray();
}
$_tmp = array_intersect_key($_value, $condition);
if (count(array_diff_assoc($_tmp, $condition)) > 0) {
return false;
}
return true;
}
/**
* @param array $attributes
* @return bool
* @throws
*/
public function update(array $attributes): bool
{
if ($this->isEmpty()) {
return $this->getLogger()->failure('No data by update', 'mysql');
}
return $this->batch()->update($attributes);
}
/**
* @param string $field
* @return array|null
*/
public function keyBy(string $field): ?array
{
$array = $this->toArray();
$column = array_flip(array_column($array, $field));
foreach ($column as $key => $value) {
$column[$key] = $array[$value];
}
return $column;
}
/**
* @param $key
* @param $value
* @return mixed
*/
public function exists($key, $value): mixed
{
foreach ($this as $item) {
if ($item->$key === $value) {
return $item;
}
}
return null;
}
/**
* @param int $start
* @param int $length
*
* @return array
*/
#[Pure] public function slice(int $start = 0, int $length = 20): array
{
if (empty($this->getItems())) {
return [];
}
if (\count($this->getItems()) < $length) {
return $this->getItems();
} else {
return array_slice($this->getItems(), $start, $length);
}
}
/**
* @return bool
*/
#[Pure] public function isEmpty(): bool
{
return $this->size() < 1;
}
/**
* @param string $field
* @param string $setKey
*
* @return array|null
*/
public function column(string $field, string $setKey = ''): ?array
{
$data = $this->toArray();
if (empty($data)) {
return [];
}
if (!empty($setKey) && is_string($setKey)) {
return array_column($data, $field, $setKey);
} else {
return array_column($data, $field);
}
}
/**
* @param string $field
*
* @return float|int|null
*/
public function sum(string $field): float|int|null
{
$array = $this->column($field);
if (empty($array)) {
return NULL;
}
return array_sum($array);
}
/**
* @return ModelInterface|array
*/
#[Pure] public function current(): ModelInterface|array
{
return current($this->getItems());
}
/**
* @return int
*/
#[Pure] public function size(): int
{
return count($this->getItems());
}
/**
* @return array
* @throws
*/
public function toArray(): array
{
$array = [];
/** @var Model $value */
foreach ($this as $value) {
$array[] = $value->toArray();
}
return $array;
}
/**
* @throws
* 批量删除
*/
public function delete(): bool
{
$model = $this->getModel();
if ($this->isEmpty()) {
return $this->getLogger()->failure('No data by delete', 'mysql');
}
if (!$model->hasPrimary()) {
throw new Exception('Must set primary key. if you want to delete data');
}
return $this->batch()->delete();
}
/**
* @return ActiveQuery
* @throws Exception
*/
private function batch(): ActiveQuery
{
return $this->makeNewQuery()->whereIn($this->getModel()->getPrimary(),
$this->column($this->getModel()->getPrimary()));
}
/**
* @param array $condition
* @return Collection
* @throws
*/
public function filter(array $condition): Collection|static
{
$_filters = [];
if (empty($condition)) {
return $this;
}
foreach ($this as $value) {
if (!$this->filterCheck($value, $condition)) {
continue;
}
$_filters[] = $value;
}
return new Collection($this->query, $this->model, $_filters);
}
/**
* @param array|ModelInterface $value
* @param array $condition
* @return bool
*/
private function filterCheck(array|ModelInterface $value, array $condition): bool
{
$_value = $value;
if ($_value instanceof ModelInterface) {
$_value = $_value->toArray();
}
$_tmp = array_intersect_key($_value, $condition);
if (count(array_diff_assoc($_tmp, $condition)) > 0) {
return false;
}
return true;
}
/**
* @param string $key
* @param mixed $value
* @return mixed
*/
public function exists(string $key, mixed $value): mixed
{
foreach ($this as $item) {
if ($item->$key === $value) {
return $item;
}
}
return null;
}
/**
* @return bool
*/
#[Pure] public function isEmpty(): bool
{
return $this->size() < 1;
}
}
+195 -153
View File
@@ -12,8 +12,9 @@ namespace Database;
use Exception;
use Kiri\Abstracts\Component;
use Kiri\Core\Json;
use PDOStatement;
use Kiri\Di\Container;
use PDO;
use Throwable;
/**
* Class Command
@@ -21,175 +22,216 @@ use PDOStatement;
*/
class Command extends Component
{
const ROW_COUNT = 'ROW_COUNT';
const FETCH = 'FETCH';
const FETCH_ALL = 'FETCH_ALL';
const EXECUTE = 'EXECUTE';
const FETCH_COLUMN = 'FETCH_COLUMN';
/** @var Connection */
public Connection $db;
public Connection $connection;
public ?string $sql = '';
public array $params = [];
/** @var ?string */
public ?string $sql = '';
/** @var array */
public array $params = [];
/** @var string */
public string $dbname = '';
/**
* @param array $params
* @throws
*/
public function __construct(array $params = [])
{
parent::__construct();
Container::configure($this, $params);
}
/**
* @return array|bool|int|string|PDOStatement|null
* @throws Exception
*/
public function incrOrDecr(): array|bool|int|string|PDOStatement|null
{
return $this->execute(static::EXECUTE);
}
/**
* @return bool
* @throws
*/
public function incrOrDecr(): bool
{
return (bool)$this->_prepare();
}
/**
* @return int|bool|array|string|null
* @throws Exception
*/
public function save(): int|bool|array|string|null
{
return $this->execute(static::EXECUTE);
}
/**
* @return bool
* @throws
*/
public function save(): bool
{
return (bool)$this->_prepare();
}
/**
* @return int|bool|array|string|null
* @throws Exception
*/
public function all(): int|bool|array|string|null
{
return $this->execute(static::FETCH_ALL);
}
/**
* @return bool|array
* @throws
*/
public function all(): bool|array
{
return $this->search('fetchAll');
}
/**
* @return array|bool|int|string|null
* @throws Exception
*/
public function one(): null|array|bool|int|string
{
return $this->execute(static::FETCH);
}
/**
* @return array|bool|null
* @throws
*/
public function one(): array|null|bool
{
return $this->search('fetch');
}
/**
* @return int|bool|array|string|null
* @throws Exception
*/
public function fetchColumn(): int|bool|array|string|null
{
return $this->execute(static::FETCH_COLUMN);
}
/**
* @return bool
* @throws Exception
*/
public function exists(): bool
{
$data = $this->search('fetch');
if (!$data) {
return false;
}
return true;
}
/**
* @return int|bool|array|string|null
* @throws Exception
*/
public function rowCount(): int|bool|array|string|null
{
return $this->execute(static::ROW_COUNT);
}
/**
* @return mixed
* @throws
*/
public function fetchColumn(): mixed
{
return $this->search('fetchColumn');
}
/**
* @return int|bool|array|string|null
* @throws Exception
*/
public function flush(): int|bool|array|string|null
{
return $this->execute(static::EXECUTE);
}
/**
* @return mixed
* @throws
*/
public function rowCount(): int
{
$data = $this->search('fetch');
/**
* @param string $type
* @return int|bool|array|string|null
* @throws Exception
*/
private function execute(string $type): int|bool|array|string|null
{
try {
$time = microtime(true);
if ($type === static::EXECUTE) {
$result = $this->db->getConnect($this->sql)->execute($this->sql,$this->params);
} else {
$result = $this->search($type);
}
if (microtime(true) - $time >= 0.02) {
$this->warning('Mysql:' . Json::encode([$this->sql, $this->params]) . (microtime(true) - $time));
}
} catch (\Throwable $exception) {
$result = $this->addError($this->sql . '. error: ' . $exception->getMessage(), 'mysql');
} finally {
$this->db->release();
return $result;
}
}
return !$data ? 0 : +current($data);
}
/**
* @param string $type
* @return array|int|bool|null
* @throws Exception
*/
private function search(string $type): array|int|bool|null
{
$pdo = $this->db->getConnect($this->sql);
if ($type === static::FETCH_COLUMN) {
$data = $pdo->fetchColumn($this->sql, $this->params);
} else if ($type === static::ROW_COUNT) {
$data = $pdo->count($this->sql, $this->params);
} else if ($type === static::FETCH_ALL) {
$data = $pdo->fetchAll($this->sql, $this->params);
} else {
$data = $pdo->fetch($this->sql, $this->params);
}
return $data;
}
/**
* @param string $method
* @return mixed
* @throws
*/
protected function search(string $method): mixed
{
$client = $this->connection->getConnection();
try {
if (($prepare = $client->prepare($this->sql)) === false) {
throw new Exception('(' . $prepare->errorInfo()[0] . ')' . $client->errorInfo()[2]);
}
$prepare->execute($this->params);
$result = $method == 'rowCount' ? $prepare->rowCount() : $prepare->{$method}(PDO::FETCH_ASSOC);
$prepare->closeCursor();
$this->connection->println($this->sql, $this->params);
return $result;
} catch (Throwable $throwable) {
if ($this->isRefresh($throwable)) return $this->search($method);
$errorMsg = $throwable->getMessage() . PHP_EOL . ' Sql: ' . $this->sql . '.' . json_encode($this->params);
return $this->getLogger()->failure($errorMsg . PHP_EOL, 'mysql');
} finally {
$this->connection->release($client);
}
}
/**
* @return int|bool|array|string|null
* @throws Exception
*/
public function delete(): int|bool|array|string|null
{
return $this->execute(static::EXECUTE);
}
/**
* @return bool
* @throws
*/
public function flush(): bool
{
return (bool)$this->_prepare();
}
/**
* @return int|bool|array|string|null
* @throws Exception
*/
public function exec(): int|bool|array|string|null
{
return $this->execute(static::EXECUTE);
}
/**
* @param array $data
* @return $this
*/
public function bindValues(array $data = []): static
{
if (!empty($data)) {
$this->params = array_merge($this->params, $data);
}
return $this;
}
/**
* @return int|bool
* @throws
*/
private function _prepare(): int|bool
{
$client = $this->connection->getConnection();
try {
if (($prepare = $client->prepare($this->sql)) === false) {
throw new Exception('(' . $prepare->errorInfo()[0] . ')' . $prepare->errorInfo()[2]);
}
if ($prepare->execute($this->params) === false) {
throw new Exception('(' . $prepare->errorInfo()[0] . ')' . $prepare->errorInfo()[2]);
}
$prepare->closeCursor();
/**
* @param $sql
* @return $this
* @throws Exception
*/
public function setSql($sql): static
{
$this->sql = $sql;
return $this;
}
$result = $client->lastInsertId();
$this->connection->println($this->sql, $this->params);
return $result == 0 ? $prepare->rowCount() : (int)$result;
} catch (Throwable $throwable) {
if ($this->isRefresh($throwable)) return $this->_prepare();
$errorMsg = $throwable->getMessage() . PHP_EOL . ' Sql: ' . $this->sql . '.' . json_encode($this->params);
return $this->getLogger()->failure($errorMsg . PHP_EOL, 'mysql');
} finally {
$this->connection->release($client);
}
}
/**
* @param Throwable $throwable
* @return bool
*/
protected function isRefresh(Throwable $throwable): bool
{
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
return true;
}
if (str_contains($throwable->getMessage(), 'Send of 14 bytes failed with errno=32 Broken pipe')) {
return true;
}
if (str_contains($throwable->getMessage(), 'Lost connection to MySQL server during query')) {
return true;
}
return false;
}
/**
* @return bool
* @throws
*/
public function delete(): bool
{
return (bool)$this->_prepare();
}
/**
* @return int|bool
*/
public function exec(): int|bool
{
return $this->_prepare();
}
/**
* @param array $data
* @return $this
*/
public function bindValues(array $data = []): static
{
if (count($data) > 0) {
$this->params = array_merge($this->params, $data);
}
return $this;
}
}
+51 -56
View File
@@ -14,69 +14,64 @@ use Kiri\Abstracts\Component;
abstract class Condition extends Component
{
protected string $column = '';
protected string $opera = '=';
protected string $column = '';
protected string $opera = '=';
protected mixed $value;
protected array $attributes = [];
/** @var array|mixed */
protected $value;
abstract public function builder();
const INT_TYPE = ['bit', 'bool', 'tinyint', 'smallint', 'mediumint', 'int', 'bigint', 'float', 'double', 'decimal', 'timestamp'];
/**
* @param string $column
*/
public function setColumn(string $column): void
{
$this->column = $column;
}
protected array $attributes = [];
/**
* @param string $opera
*/
public function setOpera(string $opera): void
{
$this->opera = $opera;
}
abstract public function builder();
/**
* @param string $column
*/
public function setColumn(string $column): void
{
$this->column = $column;
}
/**
* @param string $opera
*/
public function setOpera(string $opera): void
{
$this->opera = $opera;
}
/**
* @param $params
*/
public function setValue($params): void
{
if (is_array($params)) {
$values = [];
foreach ($params as $item => $value) {
$values[$item] = is_numeric($value) ? $value : '\'' . $value . '\'';
}
$this->value = $values;
} else {
$this->value = $this->checkIsSqlString($params);
}
}
/**
* @param $params
*/
public function setValue($params): void
{
if (is_array($params)) {
$values = [];
foreach ($params as $item => $value) {
$values[$item] = is_numeric($value) ? $value : '\'' . $value . '\'';
}
$this->value = $values;
} else {
$this->value = $this->checkIsSqlString($params);
}
}
/**
* @param $params
* @return int|string
*/
#[Pure] private function checkIsSqlString($params): int|string
{
if (is_numeric($params)) {
return $params;
}
/**
* @param $params
* @return int|string
*/
#[Pure] private function checkIsSqlString($params): int|string
{
if (is_numeric($params)) {
return $params;
}
$check = ltrim($params, '(');
$check = strtolower(substr($check, 0, 6));
if (in_array($check, ['update', 'select', 'insert', 'delete'])) {
return $params;
} else {
return sprintf('\'%s\'', $params);
}
}
$check = ltrim($params, '(');
$check = strtolower(substr($check, 0, 6));
if (in_array($check, ['update', 'select', 'insert', 'delete'])) {
return $params;
} else {
return sprintf('\'%s\'', $params);
}
}
}
+1 -1
View File
@@ -18,7 +18,7 @@ class DefaultCondition extends Condition
*/
#[Pure] public function builder(): string
{
return sprintf('%s %s %s', $this->column, $this->opera, addslashes($this->value));
return $this->column . ' ' . $this->opera . ' ' . addslashes($this->value);
}
}
+15 -16
View File
@@ -10,21 +10,20 @@ namespace Database\Condition;
class HashCondition extends Condition
{
/**
* @return string
*/
public function builder(): string
{
$array = [];
if (empty($this->value)) {
return '';
}
foreach ($this->value as $key => $value) {
if (is_null($value)) continue;
$array[] = sprintf("%s = '%s'", $key, addslashes($value));
}
return implode(' AND ', $array);
}
/**
* @return string
* @throws
*/
public function builder(): string
{
$array = [];
if (count($this->value) < 1) {
throw new \Exception('Builder data by a empty array.');
}
foreach ($this->value as $key => $value) {
$array[] = $key . '=' . addslashes($value);
}
return implode(' AND ', $array);
}
}
+12 -14
View File
@@ -3,8 +3,6 @@ declare(strict_types=1);
namespace Database\Condition;
use Database\ActiveQuery;
use Exception;
use JetBrains\PhpStorm\Pure;
/**
@@ -15,17 +13,17 @@ class InCondition extends Condition
{
/**
* @return string
* @throws Exception
*/
#[Pure] public function builder(): string
{
if (is_array($this->value)) {
return sprintf('%s IN (%s)', $this->column, implode(',', $this->value));
} else {
return sprintf('%s IN (%s)', $this->column, $this->value);
}
}
/**
* @return string
* @throws
*/
#[Pure] public function builder(): string
{
if (is_array($this->value)) {
return $this->column . ' IN (' . implode(',', $this->value) . ')';
} else {
return $this->column . ' IN (' . $this->value . ')';
}
}
}
+6 -2
View File
@@ -12,9 +12,13 @@ class JsonCondition extends Condition
{
public function builder()
{
/**
* @return bool
*/
public function builder(): bool
{
// TODO: Implement builder() method.
return \json_validate($this->value);
}
}
-2
View File
@@ -3,8 +3,6 @@ declare(strict_types=1);
namespace Database\Condition;
use Kiri\Core\Str;
/**
* Class LLikeCondition
* @package Database\Condition
-2
View File
@@ -3,8 +3,6 @@ declare(strict_types=1);
namespace Database\Condition;
use Kiri\Core\Str;
/**
* Class LikeCondition
* @package Database\Condition
+12 -11
View File
@@ -13,16 +13,17 @@ class NotInCondition extends Condition
{
/**
* @return string|null
*/
#[Pure] public function builder(): ?string
{
if (!is_array($this->value)) {
return null;
}
$value = '\'' . implode('\',\'', $this->value) . '\'';
return '`' . $this->column . '` not in(' . $value . ')';
}
/**
* @return string|null
* @throws
*/
#[Pure] public function builder(): ?string
{
if (!is_array($this->value)) {
throw new \Exception('Builder data by a empty string. need array');
}
$value = '\'' . implode('\',\'', $this->value) . '\'';
return '`' . $this->column . '` not in(' . $value . ')';
}
}
-2
View File
@@ -3,8 +3,6 @@ declare(strict_types=1);
namespace Database\Condition;
use Kiri\Core\Str;
/**
* Class NotLikeCondition
* @package Database\Condition
+1 -1
View File
@@ -21,7 +21,7 @@ class OrCondition extends Condition
*/
#[Pure] public function builder(): string
{
return sprintf('(%s) OR %s', implode(' AND ', $this->oldParams), addslashes($this->value));
return '(' . implode(' AND ', $this->oldParams) . ') OR ' . addslashes($this->value);
}
}
-2
View File
@@ -3,8 +3,6 @@ declare(strict_types=1);
namespace Database\Condition;
use Kiri\Core\Str;
/**
* Class RLikeCondition
* @package Database\Condition
+327 -282
View File
@@ -14,18 +14,23 @@ namespace Database;
use Database\Affair\BeginTransaction;
use Database\Affair\Commit;
use Database\Affair\Rollback;
use Database\Mysql\PDO;
use Database\Mysql\Schema;
use Exception;
use Kiri\Abstracts\Component;
use Kiri\Abstracts\Config;
use Kiri\Events\EventProvider;
use Kiri\Exception\NotFindClassException;
use Kiri\Kiri;
use Kiri\Annotation\Inject;
use ReflectionException;
use Kiri;
use Kiri\Server\Events\OnWorkerExit;
use Kiri\Server\Events\OnWorkerStop;
use Kiri\Abstracts\Component;
use Kiri\Di\Context;
use Kiri\Pool\Pool;
use Kiri\Events\EventProvider;
use Kiri\Error\StdoutLogger;
use Psr\Log\LoggerInterface;
use Kiri\Server\Events\OnWorkerStart;
use Kiri\Server\Events\OnTaskerStart;
use Kiri\Server\Events\OnAfterRequest;
use Kiri\Di\Inject\Container;
use Swoole\Timer;
use Database\Base\PDO;
//use PDO;
/**
* Class Connection
@@ -34,300 +39,340 @@ use Kiri\Server\Events\OnWorkerStop;
class Connection extends Component
{
public string $id = 'db';
public string $cds = '';
public string $password = '';
public string $username = '';
public string $charset = 'utf-8';
public string $tablePrefix = '';
public string $database = '';
public int $connect_timeout = 30;
public int $read_timeout = 10;
public array $pool;
/**
* @var bool
* enable database cache
*/
public bool $enableCache = false;
public string $id = 'db';
public string $cds = '';
public string $password = '';
public string $username = '';
public string $charset = 'utf-8';
public string $tablePrefix = '';
public string $database = '';
public int $timeout = 30;
public int $waite_time = 3;
public int $tick_time = 60;
public int $idle_count = 3;
public int $idle_time = 60;
public array $pool = ['max' => 10, 'min' => 1];
private int $storey = 0;
protected int $timerId = -1;
public bool $enableCache = false;
public string $cacheDriver = 'redis';
public array $attributes = [];
public array $slave = [];
protected ?\Closure $_println = null;
/**
* @var string
*/
public string $cacheDriver = 'redis';
/**
* @var StdoutLogger
*/
#[Container(LoggerInterface::class)]
public StdoutLogger $logger;
/**
* @var array
*/
public array $slaveConfig = [];
public array $attributes = [];
/**
* @param Pool $connections
*/
public function __construct(public Pool $connections)
{
parent::__construct();
$this->_println = \config('databases.logger', null);
}
private ?Schema $_schema = null;
/**
* @param string $sql
* @param array $params
* @return void
*/
public function println(string $sql, array $params = []): void
{
if (is_callable($this->_println)) {
call_user_func($this->_println, $sql, $params);
}
}
/**
* execute by __construct
* @throws Exception
*/
public function init()
{
$this->eventProvider->on(OnWorkerStop::class, [$this, 'clear_connection'], 0);
$this->eventProvider->on(OnWorkerExit::class, [$this, 'clear_connection'], 0);
$this->eventProvider->on(BeginTransaction::class, [$this, 'beginTransaction'], 0);
$this->eventProvider->on(Rollback::class, [$this, 'rollback'], 0);
$this->eventProvider->on(Commit::class, [$this, 'commit'], 0);
}
/**
* @return void
* @throws
*/
public function init(): void
{
$eventProvider = Kiri::getDi()->get(EventProvider::class);
$eventProvider->on(BeginTransaction::class, [$this, 'beginTransaction'], 0);
$eventProvider->on(Rollback::class, [$this, 'rollback'], 0);
$eventProvider->on(Commit::class, [$this, 'commit'], 0);
$eventProvider->on(OnAfterRequest::class, [$this, 'clear']);
$eventProvider->on(OnWorkerExit::class, [$this, 'disconnect']);
$eventProvider->on(OnWorkerStart::class, [$this, 'tick']);
$eventProvider->on(OnTaskerStart::class, [$this, 'tick']);
}
/**
* @param null $sql
* @return PDO
* @throws Exception
*/
public function getConnect($sql = NULL): PDO
{
return $this->getPdo($sql);
}
/**
* @return void
*/
public function tick(): void
{
$this->timerId = Timer::tick($this->tick_time, fn() => $this->checkClientHealth($this->pool()));
}
/**
* @throws Exception
*/
public function fill()
{
$connections = $this->connections();
$pool = Config::get('databases.pool.max', 10);
$connections->initConnections('Mysql:' . $this->cds, true, $pool);
if (!empty($this->slaveConfig) && $this->cds != $this->slaveConfig['cds']) {
$connections->initConnections('Mysql:' . $this->slaveConfig['cds'], false, $pool);
}
}
/**
* @param Pool $pool
* @return void
* @throws
*/
protected function checkClientHealth(Pool $pool): void
{
$pool->flush($this->getName(), $this->pool['min'] ?? 1);
$length = $pool->size($this->getName());
for ($i = 0; $i < $length; $i++) {
try {
if (($client = $this->validator($pool)) === false) {
break;
}
$pool->push($this->getName(), $client);
} catch (\Throwable $exception) {
if (!str_contains($exception->getMessage(), 'Client timeout.')) {
$this->logger->error(throwable($exception), [$this->cds]);
}
}
}
}
/**
* @param $sql
* @return PDO
* @throws Exception
*/
private function getPdo($sql): PDO
{
if ($this->isWrite($sql)) {
return $this->masterInstance();
} else {
return $this->slaveInstance();
}
}
/**
* @return mixed
* @throws ReflectionException
* @throws NotFindClassException
* @throws Exception
*/
public function getSchema(): Schema
{
if ($this->_schema === null) {
$this->_schema = Kiri::createObject([
'class' => Schema::class,
'db' => $this
]);
}
return $this->_schema;
}
/**
* @param $sql
* @return bool
*/
public function isWrite($sql): bool
{
if (empty($sql)) return false;
if (str_starts_with(strtolower($sql), 'select')) {
return false;
}
return true;
}
/**
* @return mixed
* @throws Exception
*/
public function getCacheDriver(): mixed
{
if (!$this->enableCache) {
return null;
}
return Kiri::app()->get($this->cacheDriver);
}
/**
* @return PDO
* @throws Exception
*/
public function masterInstance(): PDO
{
return $this->connections()->get([
'cds' => $this->cds,
'username' => $this->username,
'password' => $this->password,
'attributes' => $this->attributes,
'connect_timeout' => $this->connect_timeout,
'read_timeout' => $this->read_timeout,
'dbname' => $this->database,
'pool' => $this->pool
], true);
}
/**
* @return PDO
* @throws Exception
*/
public function slaveInstance(): PDO
{
if (empty($this->slaveConfig) || Db::transactionsActive()) {
return $this->masterInstance();
}
if ($this->slaveConfig['cds'] == $this->cds) {
return $this->masterInstance();
}
return $this->connections()->get($this->slaveConfig, false);
}
/**
* @return string
*/
private function getName(): string
{
return 'mysql.' . $this->cds;
}
/**
* @return \Kiri\Pool\Connection
* @throws Exception
*/
private function connections(): \Kiri\Pool\Connection
{
return Kiri::getDi()->get(\Kiri\Pool\Connection::class);
}
/**
* @param Pool $pool
* @return PDO|bool
* @throws
*/
protected function validator(Pool $pool): PDO|bool
{
/** @var $client PDO */
if (($client = $pool->get($this->getName())) === false) {
return false;
}
if ($client->query('select 1') === false) {
throw new Exception($client->errorInfo()[1]);
}
return $client;
}
/**
* @return $this
* @throws Exception
*/
public function beginTransaction(): static
{
$this->connections()->beginTransaction($this->cds);
return $this;
}
/**
* @return $this|bool
* @throws Exception
*/
public function inTransaction(): bool|static
{
return $this->connections()->inTransaction($this->cds);
}
/**
* @throws Exception
* 事务回滚
*/
public function rollback()
{
$this->connections()->rollback($this->cds);
$this->release();
}
/**
* @throws Exception
* 事务提交
*/
public function commit()
{
$this->connections()->commit($this->cds);
$this->release();
}
/**
* @param $sql
* @return PDO
* @throws Exception
*/
public function refresh($sql): PDO
{
if ($this->isWrite($sql)) {
$instance = $this->masterInstance();
} else {
$instance = $this->slaveInstance();
}
return $instance;
}
/**
* @param null $sql
* @param array $attributes
* @return Command
* @throws Exception
*/
public function createCommand($sql = null, array $attributes = []): Command
{
$command = new Command(['db' => $this, 'sql' => $sql]);
return $command->bindValues($attributes);
}
/**
* @return PDO
* @throws
*/
public function getConnection(): PDO
{
if (!$this->inTransaction()) {
return $this->getNormalClientHealth();
} else {
return $this->getTransactionClient();
}
}
/**
*
* 回收链接
* @throws
*/
public function release()
{
if (!Kiri::isWorker() && !Kiri::isProcess()) {
$this->clear_connection();
return;
}
$connections = $this->connections();
$connections->release($this->cds, true);
$connections->release($this->slaveConfig['cds'], false);
}
/**
* @return PDO
* @throws
*/
protected function getNormalClientHealth(): PDO
{
$data = $this->pool()->get($this->getName(), $this->waite_time);
if ($data === false) {
throw new Exception('Client Waite timeout.');
}
return $data;
}
/**
* @throws Exception
*/
public function recovery()
{
$connections = $this->connections();
$connections->release($this->cds, true);
$connections->release($this->slaveConfig['cds'], false);
}
/**
*
* 回收链接
* @throws
*/
public function clear_connection()
{
$connections = $this->connections();
$connections->connection_clear($this->cds, true);
$connections->connection_clear($this->slaveConfig['cds'], false);
}
/**
* @return $this
* @throws
*/
public function beginTransaction(): static
{
if ($this->storey < 0) {
$this->storey = 0;
}
$this->storey++;
return $this;
}
/**
* @throws Exception
*/
public function disconnect()
{
$connections = $this->connections();
$connections->disconnect($this->cds, true);
$connections->disconnect($this->slaveConfig['cds'], false);
}
/**
* @return PDO
* @throws
*/
public function getTransactionClient(): PDO
{
$pdo = Context::get($this->cds);
if ($pdo === null) {
/** @var PDO $pdo */
$pdo = Context::set($this->cds, $this->getNormalClientHealth());
}
if ($this->storey > 0 && !$pdo->inTransaction()) {
$pdo->beginTransaction();
}
return $pdo;
}
/**
* @return bool
* @throws
*/
public function inTransaction(): bool
{
return $this->storey > 0;
}
/**
* @throws
* 事务回滚
*/
public function rollback(): void
{
$this->storey--;
if ($this->storey == 0) {
if (!Context::exists($this->cds)) {
return;
}
$pdo = $this->getTransactionClient();
if ($pdo->inTransaction()) {
$pdo->rollback();
}
$this->release($pdo);
}
}
/**
* @throws
* 事务提交
*/
public function commit(): void
{
$this->storey--;
if ($this->storey == 0) {
if (!Context::exists($this->cds)) {
return;
}
$pdo = $this->getTransactionClient();
if ($pdo->inTransaction()) {
$pdo->commit();
}
$this->release($pdo);
}
}
/**
* @return void
* @throws
*/
public function clear(): void
{
/** @var PDO $pdo */
$pdo = Context::get($this->cds);
if ($pdo === null) {
return;
}
if ($this->inTransaction()) {
$pdo->rollback();
}
$this->release($pdo);
}
/**
* @param string $sql
* @param array $attributes
* @return Command
* @throws
*/
public function createCommand(string $sql, array $attributes = []): Command
{
return (new Command(['connection' => $this, 'sql' => $sql]))->bindValues($attributes);
}
/**
* 回收链接
* @throws
*/
public function release(PDO $pdo): void
{
if (!$this->inTransaction()) {
$this->pool()->push($this->getName(), $pdo);
}
}
/**
*
* 回收链接
* @throws
*/
public function clear_connection(): void
{
$this->pool()->flush($this->getName(), 0);
}
/**
* @throws
*/
public function disconnect(): void
{
if ($this->timerId > -1) {
Timer::clear($this->timerId);
}
$this->pool()->close($this->getName());
}
/**
* @return PDO
*/
public function newConnect(): \PDO
{
$pdo = new PDO($this->database, $this->cds, $this->username, $this->password, [
// $pdo = new \PDO('mysql:dbname=' . $this->database . ';host=' . $this->cds, $this->username, $this->password, [
\PDO::ATTR_CASE => \PDO::CASE_NATURAL,
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_ORACLE_NULLS => \PDO::NULL_NATURAL,
\PDO::ATTR_STRINGIFY_FETCHES => false,
\PDO::ATTR_EMULATE_PREPARES => true,
\PDO::ATTR_TIMEOUT => $this->timeout,
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->charset
]);
foreach ($this->attributes as $key => $attribute) {
$pdo->setAttribute($key, $attribute);
}
return $pdo;
}
/**
* @return Pool
*/
protected function pool(): Pool
{
if (!$this->connections->hasChannel($this->getName())) {
$this->connections->created($this->getName(), $this->pool['max'] ?? 1, [$this, 'newConnect']);
}
return $this->connections;
}
}
+65 -65
View File
@@ -5,12 +5,8 @@ namespace Database;
use Exception;
use Kiri\Abstracts\Config;
use Kiri;
use Kiri\Abstracts\Providers;
use Kiri\Application;
use Kiri\Exception\ConfigException;
use Kiri\Kiri;
use Kiri\Server\Events\OnWorkerStart;
/**
* Class DatabasesProviders
@@ -20,72 +16,76 @@ class DatabasesProviders extends Providers
{
/**
* @param Application $application
* @throws Exception
*/
public function onImport(Application $application)
{
$this->eventProvider->on(OnWorkerStart::class, [$this, 'createPool']);
}
/**
* @var array
*/
protected array $connections = [];
/**
* @param $name
* @return Connection
* @throws Exception
*/
public function get($name): Connection
{
return Kiri::app()->get($name);
}
/**
* @return void
* @throws
*/
public function onImport(): void
{
$main = Kiri::getDi()->get(Kiri\Application::class);
$main->command(BackupCommand::class, ImplodeCommand::class);
$databases = \config('databases.connections', []);
if (count($databases) < 1) {
return;
}
foreach ($databases as $key => $database) {
$this->set($key, $this->_settings($database));
}
}
/**
* @throws ConfigException
* @throws Exception
*/
public function createPool(OnWorkerStart $onWorkerStart)
{
$databases = Config::get('databases.connections', []);
if (empty($databases)) {
return;
}
$app = Kiri::app();
foreach ($databases as $key => $database) {
$database = $this->_settings($database);
$connection = Kiri::getDi()->create(Connection::class, [$database]);
$connection->fill();
$app->set($key, $connection);
}
}
/**
* @param string $name
* @return Connection
* @throws Exception
*/
public function get(string $name): Connection
{
return $this->connections[$name];
}
/**
* @param $database
* @return array
*/
private function _settings($database): array
{
$clientPool = $database['pool'] ?? ['min' => 1, 'max' => 5, 'tick' => 60];
return [
'id' => $database['id'],
'cds' => $database['cds'],
'username' => $database['username'],
'password' => $database['password'],
'tablePrefix' => $database['tablePrefix'],
'database' => $database['database'],
'connect_timeout' => $database['connect_timeout'] ?? 30,
'read_timeout' => $database['read_timeout'] ?? 10,
'pool' => $clientPool,
'attributes' => $database['attributes'] ?? [],
'charset' => $database['charset'] ?? 'utf8mb4',
'slaveConfig' => $database['slaveConfig']
];
}
/**
* @param string $key
* @param array $connection
* @return void
* @throws Exception
*/
protected function set(string $key, array $connection): void
{
$this->connections[$key] = Kiri::createObject($connection);
}
/**
* @param array $database
* @return array
*/
private function _settings(array $database): array
{
$clientPool = $database['pool'] ?? ['min' => 1, 'max' => 5, 'tick' => 60];
return [
'id' => $database['id'],
'cds' => $database['cds'],
'class' => Connection::class,
'username' => $database['username'],
'password' => $database['password'],
'tablePrefix' => $database['tablePrefix'],
'database' => $database['database'],
'timeout' => $database['timeout'] ?? 10,
'tick_time' => $database['tick_time'] ?? 60,
'waite_time' => $database['waite_time'] ?? 3,
'pool' => $clientPool,
'attributes' => $database['attributes'] ?? [],
'charset' => $database['charset'] ?? 'utf8mb4'
];
}
}
+216 -320
View File
@@ -9,357 +9,253 @@ declare(strict_types=1);
namespace Database;
use Closure;
use Database\Affair\BeginTransaction;
use Database\Affair\Commit;
use Database\Affair\Rollback;
use Database\Traits\QueryTrait;
use Exception;
use Kiri\Abstracts\Config;
use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException;
use Kiri;
use Throwable;
/**
* Class Db
* @package Database
*/
class Db implements ISqlBuilder
class Db extends QueryTrait implements ISqlBuilder
{
use QueryTrait;
private static bool $_inTransaction = false;
private static bool $_inTransaction = false;
/**
* @return bool
*/
public static function transactionsActive(): bool
{
return static::$_inTransaction === true;
}
/**
* @throws Exception
*/
public static function beginTransaction()
{
if (!static::transactionsActive()) {
di(EventDispatch::class)->dispatch(new BeginTransaction());
}
static::$_inTransaction = true;
}
/**
* @var Connection|null
*/
private ?Connection $connection = null;
/**
* @throws Exception
*/
public static function commit()
{
if (static::transactionsActive()) {
di(EventDispatch::class)->dispatch(new Commit());
}
static::$_inTransaction = false;
}
/**
* @param string|Connection $dbname
* @return Db
* @throws
*/
public static function connect(string|Connection $dbname): Db
{
$db = new Db();
if (is_string($dbname)) {
$db->connection = Kiri::getDi()->get(DatabasesProviders::class)->get($dbname);
} else {
$db->connection = $dbname;
}
return $db;
}
/**
* @return void
* @throws
*/
public static function beginTransaction(): void
{
fire(new BeginTransaction());
}
/**
* @throws Exception
*/
public static function rollback()
{
if (static::transactionsActive()) {
di(EventDispatch::class)->dispatch(new Rollback());
}
static::$_inTransaction = false;
}
/**
* @return void
* @throws
*/
public static function commit(): void
{
fire(new Commit());
}
/**
* @param $table
*
* @return static
*/
public static function table($table): Db|static
{
$connection = new Db();
$connection->from($table);
return $connection;
}
/**
* @return void
* @throws
*/
public static function rollback(): void
{
fire(new Rollback());
}
/**
* @param string $column
* @param string $alias
* @return string
*/
public static function any_value(string $column, string $alias = ''): string
{
if (empty($alias)) {
$alias = $column . '_any_value';
}
return 'ANY_VALUE(' . $column . ') as ' . $alias;
}
/**
* @param string $table
* @param string $database
* @return static
*/
public static function table(string $table, string $database = 'db'): Db|static
{
return self::connect($database)->from($table);
}
/**
* @param string $column
* @return string
*/
public static function increment(string $column): string
{
return '+ ' . $column;
}
/**
* @param string $column
* @param string $alias
* @return string
*/
public static function any_value(string $column, string $alias = ''): string
{
if (empty($alias)) {
$alias = $column . '_any_value';
}
return 'ANY_VALUE(' . $column . ') as ' . $alias;
}
/**
* @param string $column
* @return string
*/
public static function decrement(string $column): string
{
return '- ' . $column;
}
/**
* @return int
*/
public function count(): int
{
return $this->connection->createCommand(SqlBuilder::builder($this)->count())->rowCount();
}
/**
* @return bool
* @throws Exception
*/
public function exists(): bool
{
return $this->connection->createCommand(SqlBuilder::builder($this->limit(1))->exists())->exists();
}
/**
* @param string $sql
* @param array $attributes
* @return array|bool|int|string|null
* @throws
*/
public function fetchAll(string $sql, array $attributes = []): int|bool|array|string|null
{
return $this->connection->createCommand($sql, $attributes)->all();
}
/**
* @param string $sql
* @param array $attributes
* @return array|null
*/
public function fetch(string $sql, array $attributes = []): ?array
{
return $this->connection->createCommand($sql, $attributes)->one();
}
/**
* @param Connection|null $connection
* @return mixed
* @throws Exception
*/
public function get(Connection $connection = NULL): mixed
{
$connection = static::getDefaultConnection($connection);
return $connection->createCommand(SqlBuilder::builder($this)->one())
->all();
}
/**
* @param $column
* @return string
*/
public static function raw($column): string
{
return '`' . $column . '`';
}
/**
* @param Connection|null $connection
* @return mixed
* @throws Exception
*/
public function find(Connection $connection = NULL): mixed
{
$connection = static::getDefaultConnection($connection);
return $connection->createCommand(SqlBuilder::builder($this)->all())
->one();
}
/**
* @param Connection|NULL $connection
* @return bool|int
* @throws Exception
*/
public function count(Connection $connection = NULL): bool|int
{
$connection = static::getDefaultConnection($connection);
return $connection->createCommand(SqlBuilder::builder($this)->count())
->exec();
}
/**
* @param Connection|NULL $connection
* @return bool|int
* @throws Exception
*/
public function exists(Connection $connection = NULL): bool|int
{
$connection = static::getDefaultConnection($connection);
return $connection->createCommand(SqlBuilder::builder($this)->one())
->fetchColumn();
}
/**
* @param string $sql
* @param array $attributes
* @param Connection|null $connection
* @return array|bool|int|string|null
* @throws Exception
*/
public static function findAllBySql(string $sql, array $attributes = [], Connection $connection = NULL): int|bool|array|string|null
{
$connection = static::getDefaultConnection($connection);
return $connection->createCommand($sql, $attributes)->all();
}
/**
* @param string $sql
* @param array $attributes
* @param Connection|NULL $connection
* @return string|array|bool|int|null
* @throws Exception
*/
public static function findBySql(string $sql, array $attributes = [], Connection $connection = NULL): string|array|bool|int|null
{
$connection = static::getDefaultConnection($connection);
return $connection->createCommand($sql, $attributes)->one();
}
/**
* @param string $field
* @return array|null
* @throws Exception
*/
public function values(string $field): ?array
{
$data = $this->get();
if (empty($data) || empty($field)) {
return NULL;
}
$first = current($data);
if (!isset($first[$field])) {
return NULL;
}
return array_column($data, $field);
}
/**
* @param $field
* @return mixed
* @throws Exception
*/
public function value($field): mixed
{
$data = $this->find();
if (!empty($field) && isset($data[$field])) {
return $data[$field];
}
return $data;
}
/**
* @param Connection|null $connection
* @return bool|int
* @throws ConfigException
* @throws Exception
*/
public function delete(?Connection $connection = null): bool|int
{
$connection = static::getDefaultConnection($connection);
return $connection->createCommand($connection->getBuild()->builder($this))->delete();
}
/**
* @param string $table
* @param null $connection
* @return bool|int
* @throws ConfigException
* @throws Exception
*/
public static function drop(string $table, $connection = null): bool|int
{
$connection = static::getDefaultConnection($connection);
$sprint = sprintf('DROP TABLE `%s`.`%s`', $connection->database, $table);
return $connection->createCommand($sprint)->delete();
}
/**
* @param string $table
* @param null $connection
* @return bool|int
* @throws Exception
*/
public static function truncate(string $table, $connection = null): bool|int
{
$connection = static::getDefaultConnection($connection);
$sprint = sprintf('TRUNCATE `%s`.`%s`', $connection->database, $table);
return $connection->createCommand($sprint)->exec();
}
/**
* @param string $table
* @param Connection|NULL $connection
* @return mixed
* @throws ConfigException
* @throws Exception
*/
public static function showCreateSql(string $table, Connection $connection = NULL): mixed
{
$connection = static::getDefaultConnection($connection);
$sprint = sprintf('SHOW CREATE TABLE `%s`.`%s`', $connection->database, $table);
return $connection->createCommand($sprint)->one();
}
/**
* @param string $table
* @param Connection|NULL $connection
* @return bool|int|null
* @throws ConfigException
* @throws Exception
*/
public static function desc(string $table, Connection $connection = NULL): bool|int|null
{
$connection = static::getDefaultConnection($connection);
$sprint = sprintf('SHOW FULL FIELDS FROM `%s`.`%s`', $connection->database, $table);
return $connection->createCommand($sprint)->all();
}
/**
* @return bool
*/
public function delete(): bool
{
return $this->connection->createCommand(SqlBuilder::builder($this)->delete())->delete();
}
/**
* @param string $table
* @param Connection|NULL $connection
* @return mixed
* @throws Exception
*/
public static function show(string $table, Connection $connection = NULL): mixed
{
if (empty($table)) {
return null;
}
$connection = static::getDefaultConnection($connection);
$table = [' const TABLE = \'select * from %s where REFERENCED_TABLE_NAME=%s\';'];
return $connection->createCommand((new Query())
->select('*')
->from('INFORMATION_SCHEMA.KEY_COLUMN_USAGE')
->where(['REFERENCED_TABLE_NAME' => $table])
->getSql())->one();
}
/**
* @return bool|array|null
*/
public function first(): bool|array|null
{
return $this->connection->createCommand(SqlBuilder::builder($this)->one())->one();
}
/**
* @param null|Connection $connection
* @param null $name
* @return mixed
* @throws ConfigException
* @throws Exception
*/
public static function getDefaultConnection(?Connection $connection, $name = null): Connection
{
if ($connection instanceof Connection) {
return $connection;
}
$databases = Config::get('databases.connections', []);
if (empty($databases) || !is_array($databases)) {
throw new Exception('Please configure the database link.');
}
if (!empty($name)) {
if (!isset($databases[$name])) {
throw new Exception('Please configure the database link.');
}
return $databases[$name];
}
return current($databases);
}
/**
* @return bool|array
*/
public function get(): bool|array
{
return $this->connection->createCommand(SqlBuilder::builder($this)->all())->all();
}
/**
* @param string $sql
* @return mixed
*/
public function exec(string $sql): mixed
{
return $this->connection->createCommand($sql)->exec();
}
/**
* @param string $sql
* @return array|bool|null
*/
public function query(string $sql): array|bool|null
{
return $this->connection->createCommand($sql)->one();
}
/**
* @param string $sql
* @return array|bool
*/
public function queryAll(string $sql): array|bool
{
return $this->connection->createCommand($sql)->all();
}
/**
* @param string $table
* @return array|bool|null
* @throws
*/
public static function show(string $table): array|bool|null
{
if ($table == '') {
return null;
}
$connection = static::getDefaultConnection();
$table = [' const TABLE = \'select * from %s where REFERENCED_TABLE_NAME=%s\';'];
return $connection->createCommand((new Query())
->from('INFORMATION_SCHEMA.KEY_COLUMN_USAGE')
->where(['REFERENCED_TABLE_NAME' => $table])
->build())->one();
}
/**
* @param string $table
* @param Connection|null $connection
* @param string $database
* @return array|null
* @throws
*/
public static function desc(string $table, ?Connection $connection = null, string $database = 'db'): ?array
{
$sql = SqlBuilder::builder(new Query())->columns($table);
$connection = self::getDefaultConnection($connection, $database);
return $connection->createCommand($sql)->all();
}
/**
* @param null|Connection $connection
* @param string $database
* @return mixed
* @throws
*/
public static function getDefaultConnection(?Connection $connection = null, string $database = 'db'): Connection
{
if ($connection instanceof Connection) {
return $connection;
}
$databases = \config('databases.connections', []);
$providers = Kiri::getDi()->get(DatabasesProviders::class);
if (empty($databases) || !is_array($databases)) {
throw new Exception('Please configure the database link.');
}
return $providers->get($databases[$database]);
}
}
+11 -23
View File
@@ -3,8 +3,9 @@ declare(strict_types=1);
namespace Database;
use Exception;
use Database\Traits\HasBase;
use Exception;
use Kiri;
/**
* Class HasCount
@@ -13,27 +14,14 @@ use Database\Traits\HasBase;
class HasCount extends HasBase
{
/**
* @param $name
* @param $arguments
* @return ActiveQuery
* @throws Exception
*/
public function __call($name, $arguments): mixed
{
if (method_exists($this, $name)) {
return call_user_func([$this, $name], ...$arguments);
}
return $this->_relation->getQuery($this->model::className())->$name(...$arguments);
}
/**
* @return array|null|ModelInterface
* @throws Exception
*/
public function get(): array|ModelInterface|null
{
return $this->_relation->count($this->model::className(), $this->value);
}
/**
* @return array|null|ModelInterface
* @throws
*/
public function get(): array|ModelInterface|null
{
$relation = Kiri::getDi()->get(Relation::class);
return $relation->get($this->name);
}
}
+12 -22
View File
@@ -6,10 +6,12 @@
* Time: 13:58
*/
declare(strict_types=1);
namespace Database;
use Exception;
use Database\Traits\HasBase;
use Exception;
use Kiri;
/**
* Class HasMany
@@ -20,25 +22,13 @@ use Database\Traits\HasBase;
class HasMany extends HasBase
{
/**
* @param $name
* @param $arguments
* @return ActiveQuery
*/
public function __call($name, $arguments): mixed
{
if (method_exists($this, $name)) {
return call_user_func([$this, $name], ...$arguments);
}
return $this->_relation->getQuery($this->model::className())->$name(...$arguments);
}
/**
* @return array|null|ModelInterface
* @throws Exception
*/
public function get(): array|ModelInterface|null
{
return $this->_relation->get($this->model::className(), $this->value);
}
/**
* @return array|null|Collection
* @throws
*/
public function get(): array|Collection|null
{
$relation = Kiri::getDi()->get(Relation::class);
return $relation->get($this->name);
}
}
+11 -23
View File
@@ -9,8 +9,9 @@ declare(strict_types=1);
namespace Database;
use Exception;
use Database\Traits\HasBase;
use Exception;
use Kiri;
/**
* Class HasOne
@@ -20,26 +21,13 @@ use Database\Traits\HasBase;
class HasOne extends HasBase
{
/**
* @param $name
* @param $arguments
* @return ActiveQuery
*/
public function __call($name, $arguments): mixed
{
if (method_exists($this, $name)) {
return call_user_func([$this, $name], ...$arguments);
}
$this->_relation->getQuery($this->model::className())->$name(...$arguments);
return $this;
}
/**
* @return array|null|ModelInterface
* @throws Exception
*/
public function get(): array|ModelInterface|null
{
return $this->_relation->first($this->model::className(), $this->value);
}
/**
* @return array|null|ModelInterface
* @throws
*/
public function get(): array|ModelInterface|null
{
$relation = Kiri::getDi()->get(Relation::class);
return $relation->first($this->name);
}
}
+100
View File
@@ -0,0 +1,100 @@
<?php
declare(strict_types=1);
namespace Database;
use Co\Channel;
use Exception;
use Swoole\Coroutine;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
*
*/
class ImplodeCommand extends Command
{
/**
* @var string
*/
public string $command = 'db:implode';
/**
* @var string
*/
public string $description = 'php kiri.php db:implode --database users /Users/admin/snowflake-bi/test.sql';
/**
* @var Channel
*/
protected Channel $channel;
protected array $data;
/**
*
*/
protected function configure(): void
{
$this->setName('db:implode')
->addArgument('path', InputArgument::REQUIRED, "save to path", null)
->addOption('database', 'db', InputArgument::OPTIONAL)
->setDescription('php kiri.php db:implode --database users /Users/admin/snowflake-bi/test.sql');
$this->data = array_flip(get_html_translation_table(ENT_QUOTES | ENT_SUBSTITUTE));
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
* @throws
*/
public function execute(InputInterface $input, OutputInterface $output): int
{
try {
/** @var Connection $data */
$data = \Kiri::getDi()->get(DatabasesProviders::class)->get($input->getOption('database'));
$path = $input->getArgument('path');
if (!str_starts_with($path, '/')) {
$path = APP_PATH . $path;
}
$waite = new Coroutine\WaitGroup();
$stream = fopen($path, 'r');
if ($stream) {
while (($line = fgets($stream)) !== false) {
if (!str_starts_with(strtoupper($line), 'INSERT INTO')) {
continue;
}
$waite->add();
$insert = str_replace('&#039;', "\'", str_replace('&quot;', '"', $line));
$insert = strtr($insert, $this->data);
Coroutine::create(function () use ($waite, $insert, $data) {
Coroutine\defer(fn() => $waite->done());
$data->createCommand($insert)->exec();
});
}
fclose($stream);
}
$waite->wait();
$output->write('dump data success');
} catch (\Throwable $throwable) {
$output->writeln(throwable($throwable));
} finally {
return 1;
}
}
}
+304 -357
View File
@@ -10,14 +10,8 @@ declare(strict_types=1);
namespace Database;
use Database\Base\Getter;
use Database\Traits\HasBase;
use Database\Base\ActiveQueryInterface;
use Exception;
use Kiri\Exception\NotFindClassException;
use Kiri\Kiri;
use Kiri\ToArray;
use ReflectionException;
use Swoole\Coroutine;
defined('SAVE_FAIL') or define('SAVE_FAIL', 3227);
defined('FIND_OR_CREATE_MESSAGE') or define('FIND_OR_CREATE_MESSAGE', 'Create a new model, but the data cannot be empty.');
@@ -28,395 +22,348 @@ defined('FIND_OR_CREATE_MESSAGE') or define('FIND_OR_CREATE_MESSAGE', 'Create a
*
* @property $attributes
* @property-read $oldAttributes
*
* @mixin ActiveQueryInterface
*/
class Model extends Base\Model
{
/**
* @param string $column
* @param int $value
* @return ModelInterface|false
* @throws Exception
*/
public function increment(string $column, int $value): bool|ModelInterface
{
if (!$this->mathematics([$column => $value], '+')) {
return false;
}
$this->{$column} += $value;
return $this->refresh();
}
/**
* @param string $column
* @param int|float $value
* @return ModelInterface|false
* @throws
*/
public function increment(string $column, int|float $value): bool|ModelInterface
{
if (!$this->mathematics([$column => $value], '+')) {
return false;
}
$this->{$column} += $value;
return $this->refresh();
}
/**
* @param string $column
* @param int $value
* @return ModelInterface|false
* @throws Exception
*/
public function decrement(string $column, int $value): bool|ModelInterface
{
if (!$this->mathematics([$column => $value], '-')) {
return false;
}
$this->{$column} -= $value;
return $this->refresh();
}
/**
* @param string $column
* @param int|float $value
* @return ModelInterface|false
* @throws
*/
public function decrement(string $column, int|float $value): bool|ModelInterface
{
if (!$this->mathematics([$column => $value], '-')) {
return false;
}
$this->{$column} -= $value;
return $this->refresh();
}
/**
* @param array $columns
* @return ModelInterface|false
* @throws Exception
*/
public function increments(array $columns): bool|static
{
if (!$this->mathematics($columns, '+')) {
return false;
}
foreach ($columns as $key => $attribute) {
$this->$key += $attribute;
}
return $this;
}
/**
* @param array $columns
* @return ModelInterface|false
* @throws
*/
public function increments(array $columns): bool|static
{
if (!$this->mathematics($columns, '+')) {
return false;
}
foreach ($columns as $key => $attribute) {
$this->$key += $attribute;
}
return $this;
}
/**
* @param array $columns
* @return ModelInterface|false
* @throws Exception
*/
public function decrements(array $columns): bool|static
{
if (!$this->mathematics($columns, '-')) {
return false;
}
foreach ($columns as $key => $attribute) {
$this->$key -= $attribute;
}
return $this;
}
/**
* @param array $columns
* @return ModelInterface|false
* @throws
*/
public function decrements(array $columns): bool|static
{
if (!$this->mathematics($columns, '-')) {
return false;
}
foreach ($columns as $key => $attribute) {
$this->$key -= $attribute;
}
return $this;
}
/**
* @param array $condition
* @param array $attributes
* @return bool|ModelInterface
* @throws ReflectionException
* @throws NotFindClassException
* @throws Exception
*/
public static function findOrCreate(array $condition, array $attributes): bool|static
{
$logger = Kiri::app()->getLogger();
if (empty($attributes)) {
return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql');
}
Db::beginTransaction();
/** @var static $select */
$select = static::query()->where($condition)->first();
if (empty($select)) {
$select = duplicate(static::class);
$select->attributes = $attributes;
$select->setIsNowExample(true);
if (!$select->save()) {
Db::rollback();
return $logger->addError($select->getLastError(), 'mysql');
}
}
Db::commit();
return $select;
}
/**
* @param array $condition
* @param array $attributes
* @return bool|static
* @throws
*/
public static function findOrCreate(array $condition, array $attributes): bool|static
{
$model = static::instance();
$connection = $model->getConnection()->beginTransaction();
try {
/** @var static $select */
$select = $model::query()->where($condition)->first();
if ($select === null) {
$select = $model::populate(array_merge($condition, $attributes));
if (!$select->save()) {
throw new Exception('保存失败: ' . $model->getLastError());
}
}
$connection->commit();
return $select;
} catch (\Throwable $throwable) {
$connection->rollback();
return \Kiri::getLogger()->failure($throwable);
}
}
/**
* @param array $condition
* @param array $attributes
* @return bool|static
* @throws Exception
*/
public static function createOrUpdate(array $condition, array $attributes = []): bool|static
{
$logger = Kiri::app()->getLogger();
if (empty($attributes)) {
return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql');
}
Db::beginTransaction();
/** @var static $select */
$select = static::query()->where($condition)->first();
if (empty($select)) {
$select = duplicate(static::class);
}
$select->attributes = $attributes;
if (!$select->save()) {
Db::rollback();
$select = $logger->addError($select->getLastError(), 'mysql');
} else {
Db::commit();
}
return $select;
}
/**
* @param array $condition
* @param array $attributes
* @return bool|static
* @throws
*/
public static function createOrUpdate(array $condition, array $attributes = []): bool|static
{
$model = static::instance();
$connection = $model->getConnection()->beginTransaction();
try {
/** @var static $select */
$select = static::query()->where($condition)->first();
if (empty($select)) {
$select = static::populate($condition);
}
$select->attributes = $attributes;
if (!$select->save()) {
throw new Exception('保存失败: ' . $model->getLastError());
}
$connection->commit();
return $select;
} catch (\Throwable $throwable) {
$connection->rollback();
return \Kiri::getLogger()->failure($throwable);
}
}
/**
* @param $action
* @param $columns
* @param null|array $condition
* @return array|bool|int|string|null
* @throws Exception
*/
private function mathematics($columns, $action, ?array $condition = null): int|bool|array|string|null
{
if (empty($condition)) {
$condition = [$this->getPrimary() => $this->getPrimaryValue()];
}
$activeQuery = static::query()->where($condition);
$create = SqlBuilder::builder($activeQuery)->mathematics($columns, $action);
if (is_bool($create)) {
return false;
}
return $this->getConnection()->createCommand($create[0], $create[1])->exec();
}
/**
* @param string $name
* @param array $arguments
* @return Model|ActiveQuery
*/
public static function __callStatic(string $name, array $arguments): static|ActiveQuery
{
// TODO: Change the autogenerated stub
if (method_exists(static::class, $name)) {
return call_user_func(static::class . '::' . $name, ...$arguments);
} else {
return static::query()->{$name}(...$arguments);
}
}
/**
* @param array $fields
* @return ModelInterface|bool
* @throws Exception
*/
public function update(array $fields): static|bool
{
return $this->save($fields);
}
/**
* @param array $columns
* @param string $action
* @return array|bool|int|string|null
*/
private function mathematics(array $columns, string $action): int|bool|array|string|null
{
$condition = [$this->getPrimary() => $this->getPrimaryValue()];
$activeQuery = static::query()->where($condition);
$create = SqlBuilder::builder($activeQuery)->mathematics($columns, $action);
if (is_bool($create)) {
return false;
}
return $activeQuery->buildCommand($create)->exec();
}
/**
* @param array $data
* @return bool
* @throws Exception
*/
public static function inserts(array $data): bool
{
$result = false;
if (empty($data)) {
error('Insert data empty.', 'mysql');
} else {
$result = static::query()->batchInsert($data);
}
return $result;
}
/**
* @return bool
* @throws Exception
*/
public function delete(): bool
{
$primary = $this->getPrimary();
if (empty($primary) || !$this->hasPrimaryValue()) {
return $this->addError("Only primary key operations are supported.", 'mysql');
}
if (!$this->beforeDelete()) {
$result = static::deleteByCondition([$primary => $this->getPrimaryValue()]);
Coroutine::create(function () use ($result) {
$this->afterDelete($result);
});
return $result;
}
return false;
}
/**
* @param array $params
* @return ModelInterface|bool
* @throws
*/
public function update(array $params): static|bool
{
if (!$this->validator($this->rules(), $params) || !$this->beforeSave($this)) {
return FALSE;
}
return $this->updateInternal(...$this->arrayIntersect($params));
}
/**
* @param mixed $condition
* @param array $attributes
*
* @return bool
* @throws NotFindClassException
* @throws ReflectionException
* @throws Exception
*/
public static function updateAll(mixed $condition, array $attributes = []): bool
{
$condition = static::query()->where($condition);
return $condition->batchUpdate($attributes);
}
/**
* @param array $data
* @return bool
* @throws
*/
public static function inserts(array $data): bool
{
if (empty($data)) {
return trigger_print_error('Insert data empty.', 'mysql');
}
return static::query()->insert($data);
}
/**
* @return bool
* @throws
*/
public function delete(): bool
{
if (!$this->beforeDelete()) {
return false;
}
if ($this->hasPrimary()) {
$result = static::deleteByCondition(['id' => $this->getPrimaryValue()]);
} else {
$result = static::deleteByCondition($this->_attributes);
}
return $this->afterDelete($result);
}
/**
* @param $condition
* @return array|Collection
* @throws NotFindClassException
* @throws ReflectionException
*/
public static function get($condition): Collection|array
{
return static::query()->where($condition)->all();
}
/**
* @return array
* @throws
*/
public function toArray(): array
{
$data = $this->_attributes;
foreach ($data as $key => $datum) {
$method = 'get' . ucfirst($key) . 'Attribute';
if (!method_exists($this, $method)) {
continue;
}
$data[$key] = $this->{$method}($datum);
}
return $this->withs($data);
}
/**
* @param $condition
* @param array $attributes
*
* @return array|Collection
* @throws Exception
*/
public static function findAll($condition, array $attributes = []): array|Collection
{
$query = static::query()->where($condition);
if (!empty($attributes)) {
$query->bindParams($attributes);
}
return $query->all();
}
/**
* @param $method
* @return mixed
* @throws Exception
*/
private function withRelation($method): mixed
{
$method = $this->getRelate($method);
if (empty($method)) {
return null;
}
$resolve = $this->{$method}();
if ($resolve instanceof HasBase) {
$resolve = $resolve->get();
}
if ($resolve instanceof ToArray) {
return $resolve->toArray();
} else if (is_object($resolve)) {
return get_object_vars($resolve);
} else {
return $resolve;
}
}
/**
* @param array $data
* @return array
*/
private function withs(array $data): array
{
$with = $this->getWith();
foreach ($with as $value) {
$join = $this->withRelate($value);
if ($join instanceof \Arrayable) {
$join = $join->toArray();
}
$data[$value] = $join;
}
return $data;
}
/**
* @return array
* @throws Exception
*/
public function toArray(): array
{
$data = $this->_attributes;
$lists = di(Getter::class)->getGetter(static::class);
foreach ($lists as $key => $item) {
$data[$key] = $this->{$item}($data[$key] ?? null);
}
return $this->withRelates($data);
}
/**
* @param ModelInterface|string $modelName
* @param string $foreignKey
* @param string $localKey
* @return string
* @throws Exception
*/
private function _hasBase(ModelInterface|string $modelName, string $foreignKey, string $localKey): string
{
if (($value = $this->{$localKey}) === null) {
throw new Exception("Need join table primary key.");
}
/**
* @param $relates
* @return array
* @throws Exception
*/
private function withRelates($relates): array
{
if (empty($with = $this->getWith())) {
return $relates;
}
foreach ($with as $val) {
$relates[$val] = $this->withRelation($val);
}
return $relates;
}
$relation = $this->getRelation();
$primaryKey = $modelName . $foreignKey . $value;
if (!$relation->hasIdentification($primaryKey)) {
$relation->bindIdentification($primaryKey, $modelName::query()->where([$foreignKey => $value]));
}
return $primaryKey;
}
/**
* @param string $modelName
* @param $foreignKey
* @param $localKey
* @return HasOne|ActiveQuery
* @throws Exception
*/
public function hasOne(string $modelName, $foreignKey, $localKey): HasOne|ActiveQuery
{
if (($value = $this->{$localKey}) === null) {
throw new Exception("Need join table primary key.");
}
$relation = $this->getRelation();
return new HasOne($modelName, $foreignKey, $value, $relation);
}
/**
* @param ModelInterface|string $modelName
* @param string $foreignKey
* @param string $localKey
* @return HasOne|ActiveQuery
* @throws Exception
*/
public function hasOne(ModelInterface|string $modelName, string $foreignKey, string $localKey): HasOne|ActiveQuery
{
return new HasOne($this->_hasBase($modelName, $foreignKey, $localKey));
}
/**
* @param $modelName
* @param $foreignKey
* @param $localKey
* @return ActiveQuery|HasCount
* @throws Exception
*/
public function hasCount($modelName, $foreignKey, $localKey): ActiveQuery|HasCount
{
if (($value = $this->{$localKey}) === null) {
throw new Exception("Need join table primary key.");
}
$relation = $this->getRelation();
return new HasCount($modelName, $foreignKey, $value, $relation);
}
/**
* @param ModelInterface|string $modelName
* @param string $foreignKey
* @param string $localKey
* @return ActiveQuery|HasCount
* @throws Exception
*/
public function hasCount(ModelInterface|string $modelName, string $foreignKey, string $localKey): ActiveQuery|HasCount
{
return new HasCount($this->_hasBase($modelName, $foreignKey, $localKey));
}
/**
* @param $modelName
* @param $foreignKey
* @param $localKey
* @return ActiveQuery|HasMany
* @throws Exception
*/
public function hasMany($modelName, $foreignKey, $localKey): ActiveQuery|HasMany
{
if (($value = $this->{$localKey}) === null) {
throw new Exception("Need join table primary key.");
}
/**
* @param ModelInterface|string $modelName
* @param string $foreignKey
* @param string $localKey
* @return ActiveQuery|HasMany
* @throws Exception
*/
public function hasMany(ModelInterface|string $modelName, string $foreignKey, string $localKey): ActiveQuery|HasMany
{
return new HasMany($this->_hasBase($modelName, $foreignKey, $localKey));
}
$relation = $this->getRelation();
/**
* @param ModelInterface|string $modelName
* @param string $foreignKey
* @param string $localKey
* @return ActiveQuery|HasMany
* @throws Exception
*/
public function hasIn(ModelInterface|string $modelName, string $foreignKey, string $localKey): ActiveQuery|HasMany
{
if (($value = $this->{$localKey}) === null) {
throw new Exception("Need join table primary key.");
}
return new HasMany($modelName, $foreignKey, $value, $relation);
}
$relation = $this->getRelation();
/**
* @param $modelName
* @param $foreignKey
* @param $localKey
* @return ActiveQuery|HasMany
* @throws Exception
*/
public function hasIn($modelName, $foreignKey, $localKey): ActiveQuery|HasMany
{
if (($value = $this->{$localKey}) === null) {
throw new Exception("Need join table primary key.");
}
$primaryKey = $modelName . $foreignKey . json_encode($value, JSON_UNESCAPED_UNICODE);
if (!$relation->hasIdentification($primaryKey)) {
$relation->bindIdentification($primaryKey, $modelName::query()->whereIn($foreignKey, $value));
}
$relation = $this->getRelation();
return new HasMany($primaryKey);
}
return new HasMany($modelName, $foreignKey, $value, $relation);
}
/**
* @param bool $result
* @return bool
*/
public function afterDelete(bool $result): bool
{
return $result;
}
/**
* @param bool $result
* @return void
*/
public function afterDelete(bool $result): void
{
}
/**
* @return bool
* @throws Exception
*/
public function beforeDelete(): bool
{
return TRUE;
}
/**
* @return bool
* @throws Exception
*/
public function beforeDelete(): bool
{
return TRUE;
}
}
+79 -24
View File
@@ -17,19 +17,24 @@ namespace Database;
interface ModelInterface
{
/**
* @param $param
* @param null $db
* @return ModelInterface
*/
public static function findOne($param, $db = NULL): mixed;
/**
* @param array|string|int $param
* @return ModelInterface|null
*/
public static function findOne(array|string|int $param): ?static;
/**
* @param string|int $param
* @return ModelInterface
*/
public static function find(string|int $param): mixed;
/**
* @return mixed
*/
public function optimize(): mixed;
/**
* @param int $param
* @return ModelInterface|null
*/
public static function primary(int $param): ?static;
/**
@@ -39,23 +44,73 @@ interface ModelInterface
public static function populate(array $data): static;
/**
* @return ActiveQuery
* return a sql queryBuilder
*/
public static function query(): ActiveQuery;
/**
* @return ActiveQuery
* return a sql queryBuilder
*/
public static function query(): ActiveQuery;
/**
* @return string
*/
public function getTable(): string;
/**
* @return ?string
*/
public function getPrimary(): ?string;
/**
* @return Connection
*/
public function getConnection(): Connection;
/**
* @return string
*/
public function getTable(): string;
/**
* @return Connection
*/
public function getConnection(): Connection;
/**
* @param string $field
* @return mixed
*/
public function getAttribute(string $field): mixed;
/**
* @param string $field
* @return mixed
*/
public function getOldAttribute(string $field): mixed;
/**
* @param string $field
* @param mixed $value
* @return mixed
*/
public function setAttribute(string $field, mixed $value): mixed;
/**
* @param string $field
* @param mixed $value
* @return mixed
*/
public function setOldAttribute(string $field, mixed $value): mixed;
/**
* @return array
*/
public function getOldAttributes(): array;
/**
* @return array
*/
public function getAttributes(): array;
/**
* @return array
*/
public function getChanges(): array;
}
-406
View File
@@ -1,406 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: admin
* Date: 2019-03-18
* Time: 17:22
*/
declare(strict_types=1);
namespace Database\Mysql;
use Database\Connection;
use Database\SqlBuilder;
use Exception;
use JetBrains\PhpStorm\Pure;
use Kiri\Abstracts\Component;
use Kiri\Core\Json;
/**
* Class Columns
* @package Database\Mysql
*/
class Columns extends Component
{
/**
* @var array
* field types
*/
private array $columns = [];
/**
* @var Connection
* Mysql client
*/
public Connection $db;
/**
* @var string
* tableName
*/
public string $table = '';
/**
* @var array
* field primary key
*/
private array $_primary = [];
/**
* @var array
* by mysql field auto_increment
*/
private array $_auto_increment = [];
private array $_fields = [];
/**
* @param string $table
* @return $this
* @throws Exception
*/
public function table(string $table): static
{
$this->structure($this->table = $table);
return $this;
}
/**
* @return string
*/
public function getTable(): string
{
return $this->table;
}
/**
* @param $key
* @param $val
* @return mixed
* @throws Exception
*/
public function fieldFormat($key, $val): mixed
{
return $this->encode($val, $this->get_fields($key));
}
/**
* @param $data
* @return array
* @throws
*/
public function populate($data): array
{
$column = $this->get_fields();
foreach ($data as $key => $val) {
if (!isset($column[$key])) {
continue;
}
$data[$key] = $this->decode($val, $column[$key]);
}
return $data;
}
/**
* @param $val
* @param null $format
* @return mixed
*/
public function decode($val, $format = null): mixed
{
if (empty($format) || $val === null) {
return $val;
}
$format = strtolower($format);
if ($this->isInt($format)) {
return (int)$val;
} else if ($this->isJson($format)) {
return Json::decode($val, true);
} else if ($this->isFloat($format)) {
return (float)$val;
} else {
return stripslashes($val);
}
}
/**
* @param string $name
* @param $value
* @return mixed
* @throws Exception
*/
public function _decode(string $name, $value): mixed
{
return $this->decode($value, $this->get_fields($name));
}
/**
* @param $val
* @param null $format
* @return float|bool|int|string
* @throws Exception
*/
public function encode($val, $format = null): float|bool|int|string
{
if (empty($format)) {
return $val;
}
$format = strtolower($format);
if ($this->isInt($format)) {
return (int)$val;
} else if ($this->isJson($format)) {
return Json::encode($val);
} else if ($this->isFloat($format)) {
return (float)$val;
} else {
return addslashes($val);
}
}
/**
* @param $format
* @return bool
*/
#[Pure] public function isInt($format): bool
{
return in_array($format, ['int', 'bigint', 'tinyint', 'smallint', 'mediumint']);
}
/**
* @param $format
* @return bool
*/
#[Pure] public function isFloat($format): bool
{
return in_array($format, ['float', 'double', 'decimal']);
}
/**
* @param $format
* @return bool
*/
#[Pure] public function isJson($format): bool
{
return in_array($format, ['json']);
}
/**
* @param $format
* @return bool
*/
#[Pure] public function isString($format): bool
{
return in_array($format, ['varchar', 'char', 'text', 'longtext', 'tinytext', 'mediumtext']);
}
/**
* @return array
* @throws
*/
public function format(): array
{
return $this->columns('Default', 'Field');
}
/**
* @return mixed
* @throws Exception
*/
public function getFields(): array
{
if (empty($this->_fields)) {
$this->structure($this->table);
}
return $this->_fields[$this->table];
}
/**
* @param string $name
* @return bool
* @throws Exception
*/
public function hasField(string $name): bool
{
return array_key_exists($name, $this->getFields());
}
/**
* @return int|string|null
* @throws Exception
*/
public function getAutoIncrement(): int|string|null
{
return $this->_auto_increment[$this->table] ?? null;
}
/**
* @return array|null|string
*
* @throws Exception
*/
public function getPrimaryKeys(): array|string|null
{
if (isset($this->_auto_increment[$this->table])) {
return $this->_auto_increment[$this->table];
}
return $this->_primary[$this->table] ?? null;
}
/**
* @return array|null|string
*
* @throws Exception
*/
#[Pure] public function getFirstPrimary(): array|string|null
{
if (isset($this->_auto_increment[$this->table])) {
return $this->_auto_increment[$this->table];
}
if (isset($this->_primary[$this->table])) {
return current($this->_primary[$this->table]);
}
return null;
}
/**
* @param $name
* @param null $index
* @return array
* @throws Exception
*/
private function columns($name, $index = null): array
{
if (empty($index)) {
return array_column($this->getColumns(), $name);
} else {
return array_column($this->getColumns(), $name, $index);
}
}
/**
* @return array|static
* @throws Exception
*/
private function getColumns(): array|static
{
return $this->structure($this->getTable());
}
/**
* @param $table
* @return array|Columns
* @throws Exception
*/
private function structure($table): array|static
{
if (!isset($this->columns[$table]) || empty($this->columns[$table])) {
$column = $this->db->createCommand(SqlBuilder::builder(null)->columns($table))->all();
if (empty($column)) {
throw new Exception("The table " . $table . " not exists.");
}
return $this->columns[$table] = $this->resolve($column, $table);
}
return $this->columns[$table];
}
/**
* @param array $column
* @param $table
* @return array
*/
private function resolve(array $column, $table): array
{
foreach ($column as $key => $item) {
$this->addPrimary($item, $table);
$column[$key]['Type'] = $this->clean($item['Type']);
}
$this->_fields[$table] = array_column($column, 'Default', 'Field');
return $column;
}
/**
* @param $item
* @param $table
*/
private function addPrimary($item, $table)
{
if (!isset($this->_primary[$table])) {
$this->_primary[$table] = [];
}
if ($item['Key'] === 'PRI') {
$this->_primary[$table][] = $item['Field'];
}
$this->addIncrement($item, $table);
}
/**
* @param $item
* @param $table
*/
private function addIncrement($item, $table)
{
if ($item['Extra'] !== 'auto_increment') {
return;
}
$this->_auto_increment[$table] = $item['Field'];
}
/**
* @param $type
* @return string
*/
public function clean($type): string
{
if (!str_contains($type, ')')) {
return $type;
}
$replace = preg_replace('/\(\d+(,\d+)?\)(\s+\w+)*/', '', $type);
if (str_contains($replace, ' ')) {
$replace = explode(' ', $replace)[1];
}
return $replace;
}
/**
* @param null $field
* @return array|string|null
* @throws Exception
*/
public function get_fields($field = null): array|string|null
{
$fields = $this->getAllField();
if (empty($field)) {
return $fields;
}
if (isset($fields[$field])) {
return strtolower($fields[$field]);
}
return null;
}
/**
* @return array
* @throws Exception
*/
public function getAllField(): array
{
return $this->columns('Type', 'Field');
}
}
-324
View File
@@ -1,324 +0,0 @@
<?php
namespace Database\Mysql;
use Exception;
use Kiri\Abstracts\Config;
use Kiri\Abstracts\Logger;
use Kiri\Kiri;
use Kiri\Pool\StopHeartbeatCheck;
use PDOStatement;
use Swoole\Timer;
/**
*
*/
class PDO implements StopHeartbeatCheck
{
const DB_ERROR_MESSAGE = 'The system is busy, please try again later.';
private ?\PDO $pdo = null;
private int $_transaction = 0;
private int $_timer = -1;
private int $_last = 0;
public string $dbname;
public string $cds;
public string $username;
public string $password;
public string $charset;
public int $connect_timeout;
public int $read_timeout;
public array $attributes = [];
/**
* @param array $config
*/
public function __construct(array $config)
{
$this->dbname = $config['dbname'];
$this->cds = $config['cds'];
$this->username = $config['username'];
$this->password = $config['password'];
$this->connect_timeout = $config['connect_timeout'] ?? 30;
$this->read_timeout = $config['read_timeout'] ?? 10;
$this->charset = $config['charset'] ?? 'utf8mb4';
$this->attributes = $config['attributes'] ?? [];
}
public function init()
{
$this->heartbeat_check();
}
/**
* @return bool
*/
public function inTransaction(): bool
{
return $this->_transaction > 0;
}
/**
*
*/
public function heartbeat_check(): void
{
if (env('state', 'start') == 'exit') {
return;
}
if ($this->_timer === -1) {
$this->_timer = Timer::tick(1000, fn() => $this->waite());
}
}
/**
* @throws Exception
*/
private function waite(): void
{
try {
if (env('state', 'start') == 'exit') {
Kiri::getDi()->get(Logger::class)->critical('timer end');
$this->stopHeartbeatCheck();
}
if (time() - $this->_last > (int)Config::get('databases.pool.tick', 60)) {
$this->stopHeartbeatCheck();
$this->pdo = null;
}
} catch (\Throwable $throwable) {
error($throwable);
}
}
/**
*
*/
public function stopHeartbeatCheck(): void
{
if ($this->_timer > -1) {
Timer::clear($this->_timer);
}
$this->_timer = -1;
}
/**
*
*/
public function beginTransaction()
{
if ($this->_transaction == 0) {
$this->_pdo()->beginTransaction();
}
$this->_transaction++;
}
/**
*
*/
public function commit()
{
if ($this->_transaction == 0) {
$this->_pdo()->commit();
}
$this->_transaction--;
}
/**
*
*/
public function rollback()
{
if ($this->_transaction == 0) {
$this->_pdo()->rollBack();
}
$this->_transaction--;
}
/**
* @param string $sql
* @param array $params
* @return bool|array|null
* @throws Exception
*/
public function fetchAll(string $sql, array $params = []): bool|null|array
{
$pdo = $this->queryPrev($sql, $params);
$result = $pdo->fetchAll(\PDO::FETCH_ASSOC);
$pdo->closeCursor();
return $result;
}
/**
* @param string $sql
* @param array $params
* @return bool|array|null
* @throws Exception
*/
public function fetch(string $sql, array $params = []): bool|null|array
{
$pdo = $this->queryPrev($sql, $params);
$result = $pdo->fetch(\PDO::FETCH_ASSOC);
$pdo->closeCursor();
return $result;
}
/**
* @param string $sql
* @param array $params
* @return bool|array|null
* @throws \Exception
*/
public function fetchColumn(string $sql, array $params = []): bool|null|array
{
$pdo = $this->queryPrev($sql, $params);
$result = $pdo->fetchColumn(\PDO::FETCH_ASSOC);
$pdo->closeCursor();
return $result;
}
/**
* @param string $sql
* @param array $params
* @return int
* @throws Exception
*/
public function count(string $sql, array $params = []): int
{
$pdo = $this->queryPrev($sql, $params);
$result = $pdo->rowCount();
$pdo->closeCursor();
return $result;
}
/**
* @param string $sql
* @param array $params
* @return PDOStatement
* @throws Exception
*/
private function queryPrev(string $sql, array $params = []): PDOStatement
{
$this->_last = time();
try {
if (($statement = $this->_pdo()->query($sql)) === false) {
throw new Exception($this->_pdo()->errorInfo()[1]);
}
return $this->bindValue($statement, $params);
} catch (\PDOException | \Throwable $throwable) {
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
$this->pdo = null;
return $this->queryPrev($sql, $params);
}
throw new Exception($throwable->getMessage());
}
}
/**
* @param PDOStatement $statement
* @param array $params
* @return PDOStatement
*/
private function bindValue(PDOStatement $statement, array $params = []): PDOStatement
{
if (empty($params)) return $statement;
foreach ($params as $key => $param) {
$statement->bindValue($key, $param);
}
return $statement;
}
/**
* @param string $sql
* @param array $params
* @return int
* @throws Exception
*/
public function execute(string $sql, array $params = []): int
{
$this->_last = time();
$pdo = $this->_pdo();
if (!(($prepare = $pdo->prepare($sql)) instanceof PDOStatement)) {
throw new Exception($prepare->errorInfo()[2] ?? static::DB_ERROR_MESSAGE);
}
if ($prepare->execute($params) === false) {
throw new Exception($prepare->errorInfo()[2] ?? static::DB_ERROR_MESSAGE);
}
$result = (int)$pdo->lastInsertId();
$prepare->closeCursor();
if ($result == 0) {
return true;
}
return $result;
}
/**
* @return \PDO
*/
public function _pdo(): \PDO
{
if ($this->_timer === -1) {
$this->heartbeat_check();
}
if (!($this->pdo instanceof \PDO)) {
$this->pdo = $this->newClient();
}
return $this->pdo;
}
/**
* @return \PDO
*/
private function newClient(): \PDO
{
$link = new \PDO('mysql:dbname=' . $this->dbname . ';host=' . $this->cds, $this->username, $this->password, [
\PDO::ATTR_EMULATE_PREPARES => false,
\PDO::ATTR_CASE => \PDO::CASE_NATURAL,
\PDO::ATTR_TIMEOUT => $this->connect_timeout,
\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->charset
]);
$link->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$link->setAttribute(\PDO::ATTR_STRINGIFY_FETCHES, false);
$link->setAttribute(\PDO::ATTR_ORACLE_NULLS, \PDO::NULL_EMPTY_STRING);
if (!empty($this->attributes) && is_array($this->attributes)) {
foreach ($this->attributes as $key => $attribute) {
$link->setAttribute($key, $attribute);
}
}
return $link;
}
}
-36
View File
@@ -1,36 +0,0 @@
<?php
declare(strict_types=1);
namespace Database\Mysql;
use Exception;
use Kiri\Abstracts\Component;
use Database\Connection;
/**
* Class Schema
* @package Database\Mysql
*/
class Schema extends Component
{
/** @var ?Connection */
public ?Connection $db = null;
/** @var ?Columns $_column*/
private ?Columns $_column = null;
/**
* @return Columns|null
* @throws Exception
*/
public function getColumns(): ?Columns
{
if ($this->_column === null) {
$this->_column = new Columns(['db' => $this->db]);
}
return $this->_column;
}
}
-29
View File
@@ -1,29 +0,0 @@
<?php
declare(strict_types=1);
namespace Database\Orm;
use Database\Traits\Builder;
use Exception;
/**
* Trait Condition
* @package Database\Orm
*/
trait Condition
{
use Builder;
/**
* @param $query
* @return string
* @throws Exception
*/
public function getWhere($query): string
{
return $this->where($query);
}
}
-204
View File
@@ -1,204 +0,0 @@
<?php
declare(strict_types=1);
namespace Database;
use Closure;
use Exception;
use Kiri\Abstracts\Component;
/**
* Class Pagination
* @package Database
*/
class Pagination extends Component
{
/** @var ActiveQuery */
private ActiveQuery $activeQuery;
/** @var int 从第几个开始查 */
private int $_offset = 0;
/** @var int 每页数量 */
private int $_limit = 100;
/** @var int 最大查询数量 */
private int $_max = 0;
/** @var int 当前已查询数量 */
private int $_length = 0;
/** @var Closure */
private Closure $_callback;
/**
* PaginationIteration constructor.
* @param ActiveQuery $activeQuery
* @param array $config
* @throws Exception
*/
public function __construct(ActiveQuery $activeQuery, array $config = [])
{
parent::__construct($config);
$this->activeQuery = $activeQuery;
}
public function clean()
{
unset($this->activeQuery, $this->_callback, $this->_group);
$this->_offset = 0;
$this->_limit = 100;
$this->_max = 0;
$this->_length = 0;;
}
/**
* recover class by clone
*/
public function __clone()
{
$this->clean();
}
/**
* @param array|Closure $callback
* @throws Exception
*/
public function setCallback(array|Closure $callback)
{
if (!is_callable($callback, true)) {
throw new Exception('非法回调函数~');
}
$this->_callback = $callback;
}
/**
* @param int $number
* @return Pagination
*/
public function setOffset(int $number): static
{
if ($number < 0) {
$number = 0;
}
$this->_offset = $number;
return $this;
}
/**
* @param int $number
* @return Pagination
*/
public function setLimit(int $number): static
{
if ($number < 1) {
$number = 100;
} else if ($number > 5000) {
$number = 5000;
}
$this->_limit = $number;
return $this;
}
/**
* @param int $number
* @return Pagination
*/
public function setMax(int $number): static
{
if ($number < 0) {
return $this;
}
$this->_max = $number;
return $this;
}
/**
* @param array $param
* @return void
* @throws Exception
*/
public function plunk(array $param = [])
{
$this->loop($param);
}
/**
* 轮训
* @param $param
* @return array
* @throws Exception
*/
public function loop($param): array
{
if ($this->_max > 0 && $this->_length >= $this->_max) {
return $this->output();
}
[$length, $data] = $this->get();
$this->executed($data, $param);
unset($data);
if ($length < $this->_limit) {
return $this->output();
}
return $this->loop($param);
}
/**
* @return array
*/
public function output(): array
{
return [];
}
/**
* @param $data
* @param $param
* @throws Exception
*/
private function executed($data, $param): void
{
try {
call_user_func($this->_callback, $data, $param);
} catch (\Throwable $exception) {
$this->addError($exception, 'throwable');
}
}
/**
* @return array|Collection
*/
private function get(): Collection|array
{
if ($this->_max > 0 && $this->_length + $this->_limit > $this->_max) {
$this->_limit = $this->_length + $this->_limit - $this->_max;
}
$data = $this->activeQuery->limit($this->_offset, $this->_limit)->get();
$this->_offset += $this->_limit;
if (is_array($data)) {
$size = count($data);
} else {
$size = $data->size();
}
$this->_length += $size;
return [$size, $data];
}
}
+9 -30
View File
@@ -11,44 +11,23 @@ namespace Database;
use Database\Traits\QueryTrait;
use Exception;
/**
* Class Query
* @package Database
*/
class Query implements ISqlBuilder
class Query extends QueryTrait implements ISqlBuilder
{
use QueryTrait;
/**
* @throws Exception
*/
public function __construct()
{
$this->builder = SqlBuilder::builder($this);
}
/**
* @return string
* @throws Exception
*/
public function getSql(): string
{
return $this->builder->get();
}
/**
* @return string
* @throws Exception
*/
public function getCondition(): string
{
return $this->builder->getCondition();
}
/**
* @return string
* @throws
*/
public function getCondition(): string
{
return $this->builder->getCondition();
}
}
+70 -85
View File
@@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Database;
use Exception;
use Kiri\Abstracts\Component;
use Kiri\Di\Context;
/**
* Class Relation
@@ -14,98 +14,83 @@ use Kiri\Abstracts\Component;
class Relation extends Component
{
private array $_relations = [];
/** @var ActiveQuery[] $_query */
private array $_query = [];
/** @var ActiveQuery[] $_query */
private array $_query = [];
/**
* @param string $identification
* @param ActiveQuery $query
* @return $this
*/
public function bindIdentification(string $identification, ActiveQuery $query): static
{
$this->_query[$identification] = $query;
return $this;
}
/**
* @param string $identification
* @param ActiveQuery $query
* @return $this
*/
public function bindIdentification(string $identification, ActiveQuery $query): static
{
$this->_query[$identification] = $query;
return $this;
}
/**
* @param string $identification
* @return bool
*/
public function hasIdentification(string $identification): bool
{
return isset($this->_query[$identification]) && $this->_query[$identification] instanceof ActiveQuery;
}
/**
* @param string $name
* @return ActiveQuery|null
*/
public function getQuery(string $name): ?ActiveQuery
{
return $this->_query[$name] ?? null;
}
/**
* @param string $name
* @return ActiveQuery|null
*/
public function getQuery(string $name): ?ActiveQuery
{
return $this->_query[$name] ?? null;
}
/**
* @param string $identification
* @param $localValue
* @return mixed
* @throws Exception
*/
public function first(string $identification, $localValue): mixed
{
$_identification = $identification . '_first_' . $localValue;
if (isset($this->_relations[$_identification]) && $this->_relations[$_identification] !== null) {
return $this->_relations[$_identification];
}
$activeModel = $this->_query[$identification]->first();
if (empty($activeModel)) {
return null;
}
return $this->_relations[$_identification] = $activeModel;
}
/**
* @param string $_identification
* @return mixed
* @throws
*/
public function first(string $_identification): mixed
{
if (Context::exists($_identification)) {
return Context::get($_identification);
}
$activeModel = $this->_query[$_identification]->first();
unset($this->_query[$_identification]);
return Context::set($_identification, $activeModel);
}
/**
* @param string $identification
* @param $localValue
* @return mixed
* @throws Exception
*/
public function count(string $identification, $localValue): mixed
{
$_identification = $identification . '_count_' . $localValue;
if (isset($this->_relations[$_identification]) && $this->_relations[$_identification] !== null) {
return $this->_relations[$_identification];
}
$activeModel = $this->_query[$identification]->count();
if (empty($activeModel)) {
return null;
}
return $this->_relations[$_identification] = $activeModel;
}
/**
* @param string $_identification
* @return mixed
*/
public function count(string $_identification): mixed
{
if (Context::exists($_identification)) {
return Context::get($_identification);
}
$activeModel = $this->_query[$_identification]->count();
unset($this->_query[$_identification]);
return Context::set($_identification, $activeModel);
}
/**
* @param string $identification
* @param $localValue
* @return mixed
*/
public function get(string $identification, $localValue): mixed
{
if (is_array($localValue)) {
$_identification = $identification . '_get_' . implode('_', $localValue);
} else {
$_identification = $identification . '_get_' . $localValue;
}
if (isset($this->_relations[$_identification]) && $this->_relations[$_identification] !== null) {
return $this->_relations[$_identification];
}
$activeModel = $this->_query[$identification]->get();
if (empty($activeModel)) {
return null;
}
return $this->_relations[$_identification] = $activeModel;
}
/**
* @param string $_identification
* @return mixed
* @throws
*/
public function get(string $_identification): mixed
{
if (Context::exists($_identification)) {
return Context::get($_identification);
}
$activeModel = $this->_query[$_identification]->get();
unset($this->_query[$_identification]);
return Context::set($_identification, $activeModel);
}
}
+345 -309
View File
@@ -1,12 +1,12 @@
<?php
<?php /** @noinspection ALL */
declare(strict_types=1);
namespace Database;
use Database\Traits\Builder;
use Exception;
use JetBrains\PhpStorm\Pure;
use Kiri;
use Kiri\Abstracts\Component;
@@ -17,359 +17,395 @@ use Kiri\Abstracts\Component;
class SqlBuilder extends Component
{
use Builder;
/**
* @var ActiveQuery|Query|ISqlBuilder|null
*/
public ActiveQuery|Query|ISqlBuilder|null $query;
public ActiveQuery|Query|null $query;
/**
* @param ActiveQuery|Query|ISqlBuilder|null $config
*/
public function __construct(ActiveQuery|Query|null|ISqlBuilder $config)
{
parent::__construct();
$this->query = $config;
}
/**
* @param ISqlBuilder|null $query
* @return $this
* @throws Exception
*/
public static function builder(ISqlBuilder|null $query): static
{
return new static(['query' => $query]);
}
/**
* @param ISqlBuilder|null $query
* @return $this
* @throws
*/
public static function builder(ISqlBuilder|null $query): static
{
return new static($query);
}
/**
* @return string
* @throws Exception
*/
public function getCondition(): string
{
return $this->conditionToString();
}
/**
* @return string
* @throws
*/
public function getCondition(): string
{
return $this->where($this->query->getWhere());
}
/**
* @param array $compiler
* @return string
* @throws Exception
*/
public function hashCompiler(array $compiler): string
{
return $this->where($compiler);
}
/**
* @param array $compiler
* @return string
* @throws
*/
public function hashCompiler(array $compiler): string
{
return $this->where($compiler);
}
/**
* @param array $attributes
* @return bool|array
* @throws Exception
*/
public function update(array $attributes): bool|array
{
[$string, $array] = $this->builderParams($attributes);
return $this->__updateBuilder($string, $array);
}
/**
* @param array $attributes
* @return bool|array
* @throws
*/
public function update(array $attributes): bool|string
{
$conditions = $this->query->getParams();
$this->query->setParams([]);
$data = $this->__updateBuilder($this->makeParams($attributes));
foreach ($conditions as $condition) {
$this->query->pushParam($condition);
}
return $data;
}
/**
* @param array $attributes
* @param string $opera
* @return bool|array
* @throws Exception
*/
public function mathematics(array $attributes, string $opera = '+'): bool|array
{
$string = [];
foreach ($attributes as $attribute => $value) {
$string[] = $attribute . '=' . $attribute . $opera . $value;
}
return $this->__updateBuilder($string, []);
}
/**
* @param array $attributes
* @param string $opera
* @return bool|array
* @throws
*/
public function mathematics(array $attributes, string $opera = '+'): bool|string
{
$string = [];
foreach ($attributes as $attribute => $value) {
$string[] = $attribute . '=' . $attribute . $opera . $value;
}
return $this->__updateBuilder($string);
}
/**
* @param array $string
* @param array $params
* @return array|bool
* @throws Exception
*/
private function __updateBuilder(array $string, array $params): array|bool
{
if (empty($string)) {
return $this->addError('None data update.');
}
$condition = $this->conditionToString();
if (!empty($condition)) {
$condition = ' WHERE ' . $condition;
}
$update = 'UPDATE ' . $this->tableName() . ' SET ' . implode(',', $string) . $condition;
$update .= $this->builderLimit($this->query, false);
return [$update, $params];
}
/**
* @param array $string
* @return string|bool
* @throws
*/
private function __updateBuilder(array $string): string|bool
{
if (empty($string)) {
return Kiri::getLogger()->failure('None data update.');
}
return 'UPDATE ' . $this->query->getFrom() . ' SET ' . implode(',', $string) . $this->make();
}
/**
* @param array $attributes
* @param false $isBatch
* @return array
* @throws Exception
*/
public function insert(array $attributes, bool $isBatch = false): array
{
$update = 'INSERT INTO ' . $this->tableName();
if ($isBatch === false) {
$attributes = [$attributes];
}
$update .= '(' . implode(',', $this->getFields($attributes)) . ') VALUES ';
/**
* @param array $attributes
* @param false $isBatch
* @return array
* @throws
*/
public function insert(array $attributes, bool $isBatch = false): string
{
$update = 'INSERT INTO ' . $this->query->getFrom();
if ($isBatch === false) {
$attributes = [$attributes];
}
$update .= '(' . implode(',', $this->getFields($attributes)) . ') VALUES ';
$order = 0;
$keys = $params = [];
foreach ($attributes as $attribute) {
[$_keys, $params] = $this->builderParams($attribute, true, $params, $order);
$keys = [];
foreach ($attributes as $attribute) {
$_keys = $this->makeParams($attribute, true);
$keys[] = implode(',', $_keys);
$order++;
}
return [$update . '(' . implode('),(', $keys) . ')', $params];
}
$keys[] = implode(',', $_keys);
}
return $update . '(' . implode('),(', $keys) . ')';
}
/**
* @return string
* @throws Exception
*/
public function delete(): string
{
$delete = sprintf('DELETE FROM %s ', $this->query->modelClass->getTable());
$this->query->from = null;
return $delete . ' WHERE ' . $this->_prefix(true);
}
/**
* @return string
* @throws
*/
public function delete(): string
{
return 'DELETE FROM ' . $this->query->getFrom() . $this->make();
}
/**
* @param $attributes
* @return array
*/
#[Pure] private function getFields($attributes): array
{
return array_keys(current($attributes));
}
/**
* @param $attributes
* @return array
*/
#[Pure] private function getFields(array $attributes): array
{
return array_keys(current($attributes));
}
/**
* @param array $attributes
* @param bool $isInsert
* @param array $params
* @param int $order
* @return array[]
* a=:b,
*/
#[Pure] private function builderParams(array $attributes, bool $isInsert = false, array $params = [], int $order = 0): array
{
$keys = [];
foreach ($attributes as $key => $value) {
if ($isInsert === true) {
$keys[] = ':' . $key . $order;
$params[$key . $order] = $value;
} else {
[$keys, $params] = $this->resolveParams($key, $value, $order, $params, $keys);
}
}
return [$keys, $params];
}
/**
* @param array $attributes
* @param bool $isInsert
* @return array[]
* a=:b,
*/
private function makeParams(array $attributes, bool $isInsert = false): array
{
$keys = [];
foreach ($attributes as $key => $value) {
if ($isInsert === true) {
$keys[] = '?';
$this->query->pushParam($value);
} else {
$keys = $this->resolveParams($key, $value, $keys);
}
}
return $keys;
}
/**
* @param string $key
* @param mixed $value
* @param int $order
* @param array $params
* @param array $keys
* @return array
*/
private function resolveParams(string $key, mixed $value, int $order, array $params, array $keys): array
{
if (
str_starts_with($value, '+ ') ||
str_starts_with($value, '- ')
) {
$keys[] = $key . '=' . $key . ' ' . $value;
} else {
$params[$key . $order] = $value;
$keys[] = $key . '=:' . $key . $order;
}
return [$keys, $params];
}
/**
* @param string $key
* @param mixed $value
* @param array $keys
* @return array
*/
private function resolveParams(string $key, mixed $value, array $keys): array
{
if (is_null($value)) {
return $keys;
}
if (is_string($value) && $this->isMath($value)) {
$keys[] = $key . '=' . $key . ' ' . $value;
} else {
$this->query->pushParam($value);
$keys[] = $key . '= ?';
}
return $keys;
}
/**
* @return string
* @throws Exception
*/
public function one(): string
{
$this->query->limit(0, 1);
if (empty($this->query->from) && !empty($this->query->modelClass)) {
$this->query->from($this->query->getTable());
}
return $this->_prefix(true);
}
/**
* @param string $value
* @return bool
*/
private function isMath(string $value): bool
{
return str_starts_with($value, '+ ') || str_starts_with($value, '- ');
}
/**
* @return string
* @throws Exception
*/
public function all(): string
{
if (empty($this->query->from) && !empty($this->query->modelClass)) {
$this->query->from($this->query->getTable());
}
return $this->_prefix(true);
}
/**
* @return string
* @throws
*/
public function one(): string
{
return $this->makeSelect($this->query->getSelect()) . $this->make() . $this->makeLimit($this->query->limit(1));
}
/**
* @return string
* @throws Exception
*/
public function count(): string
{
if (empty($this->query->from) && !empty($this->query->modelClass)) {
$this->query->from($this->query->getTable());
}
return $this->_prefix(false, true);
}
/**
* @return string
* @throws
*/
public function all(): string
{
return $this->makeSelect($this->query->getSelect()) . $this->make() . $this->makeLimit($this->query);
}
/**
* @param $table
* @return string
*/
public function columns($table): string
{
return 'SHOW FULL FIELDS FROM ' . $table;
}
/**
* @return string
* @throws
*/
public function count(): string
{
return $this->makeSelect(['COUNT(*)']) . $this->make();
}
/**
* @param bool $hasOrder
* @param bool $isCount
* @return string
* @throws Exception
*/
private function _prefix(bool $hasOrder = false, bool $isCount = false): string
{
$select = '';
if (!empty($this->query->from)) {
$select = $this->_selectPrefix($isCount);
}
$select = $this->_wherePrefix($select);
if (!empty($this->query->attributes) && is_array($this->query->attributes)) {
$select = strtr($select, $this->query->attributes);
}
if (!empty($this->query->group)) {
$select .= $this->builderGroup($this->query->group);
}
if ($hasOrder === true && !empty($this->query->order)) {
$select .= $this->builderOrder($this->query->order);
}
$sql = $select . $this->builderLimit($this->query);
if ($this->query->lock) {
$sql .= ' FOR UPDATE';
}
return $sql;
}
/**
* @return string
* @throws
*/
public function exists(): string
{
return $this->makeSelect(['0']) . $this->make();
}
/**
* @param $select
* @return string
* @throws Exception
*/
private function _wherePrefix($select): string
{
$condition = $this->conditionToString();
if (empty($condition)) {
return $select;
} else if (empty($select)) {
return $condition;
}
return sprintf('%s WHERE %s', $select, $condition);
}
/**
* @param string $table
* @return string
*/
public function columns(string $table): string
{
return 'SHOW FULL FIELDS FROM ' . $table;
}
/**
* @param bool $isCount
* @return string
* @throws Exception
*/
private function _selectPrefix(bool $isCount): string
{
$select = $this->builderSelect($this->query->select, $isCount) . ' FROM ' . $this->tableName();
if (!empty($this->query->alias)) {
$select .= $this->builderAlias($this->query->alias);
}
if (!empty($this->query->join)) {
$select .= $this->builderJoin($this->query->join);
}
return $select;
}
/**
* @return string
* @throws
*/
private function make(): string
{
$select = $this->makeCondition();
$select .= $this->makeGroup();
$select .= $this->makeOrder();
return $select;
}
/**
* @param array $select
* @return string
*/
private function makeSelect(array $select = ['*']): string
{
$select = "SELECT " . implode(',', $select) . " FROM " . $this->query->getFrom();
if ($this->query->getAlias() != "") {
$select .= " AS " . $this->query->getAlias();
}
if (count($this->query->getJoin()) > 0) {
$select .= ' ' . implode(' ', $this->query->getJoin());
}
return $select;
}
/**
* @param false $isCount
* @return string
* @throws Exception
*/
public function get(bool $isCount = false): string
{
if ($isCount === false) {
return $this->all();
}
return $this->count();
}
/**
* @return string
*/
private function makeGroup(): string
{
if ($this->query->getGroup() != "") {
return ' GROUP BY ' . $this->query->getGroup();
}
return '';
}
/**
* @return string
* @throws Exception
*/
public function truncate(): string
{
return sprintf('TRUNCATE %s', $this->tableName());
}
/**
* @return string
*/
private function makeOrder(): string
{
if (count($this->query->getOrder()) > 0) {
return ' ORDER BY ' . implode(',', $this->query->getOrder());
}
return '';
}
/**
* @return string
* @throws Exception
*/
private function conditionToString(): string
{
return $this->where($this->query->where);
}
/**
* @return string
*/
private function makeCondition(): string
{
$condition = $this->where($this->query->getWhere());
if (empty($condition)) {
return '';
}
return ' WHERE ' . $condition;
}
/**
* @return string
* @throws Exception
*/
public function tableName(): string
{
if ($this->query->from instanceof \Closure) {
$this->query->from = sprintf('(%s)', $this->query->makeClosureFunction($this->query->from));
}
if ($this->query->from instanceof ActiveQuery) {
$this->query->from = sprintf('%s', SqlBuilder::builder($this->query->from)->get($this->query->from));
}
if (empty($this->query->from)) {
return $this->query->modelClass->getTable();
}
return $this->query->from;
}
private function makeLimit(): string
{
if ($this->query->getOffset() >= 0 && $this->query->getLimit() >= 1) {
return ' LIMIT ' . $this->query->getOffset() . ',' . $this->query->getLimit();
}
return '';
}
/**
* @param false $isCount
* @return string
* @throws
*/
public function get(bool $isCount = false): string
{
if ($isCount === false) {
return $this->all();
}
return $this->count();
}
/**
* @return string
* @throws
*/
public function truncate(): string
{
return sprintf('TRUNCATE %s', $this->query->getFrom());
}
/**
* @param array $where
* @return string
*/
private function where(array $where): string
{
if (count($where) < 1) {
return '';
}
$_tmp = [];
foreach ($where as $key => $value) {
$_tmp[] = $this->resolveCondition($key, $value);
}
return implode(' AND ', $_tmp);
}
/**
* @param string $field
* @param mixed $condition
* @return string
*/
private function resolveCondition(string|int $field, mixed $condition): string
{
if (is_string($field)) {
$this->query->pushParam($condition);
return $field . ' = ?';
} else if (is_string($condition)) {
return $condition;
} else {
return implode(' AND ', $this->_hashMap($condition));
}
}
/**
* @param $condition
* @return array
*/
private function _hashMap(array $condition): array
{
$_array = [];
foreach ($condition as $key => $value) {
$this->query->pushParam($value);
$_array[] = $key . '= ?';
}
return $_array;
}
}
-232
View File
@@ -1,232 +0,0 @@
<?php
namespace Database\Traits;
use Database\ActiveQuery;
use Database\Base\ConditionClassMap;
use Database\Condition\HashCondition;
use Database\Condition\OrCondition;
use Database\Query;
use Exception;
use JetBrains\PhpStorm\Pure;
use Kiri\Exception\NotFindClassException;
use Kiri\Kiri;
use ReflectionException;
/**
* Trait Builder
* @package Database\Traits
*/
trait Builder
{
/**
* @param $alias
* @return string
*/
private function builderAlias($alias): string
{
return " AS " . $alias;
}
/**
* @param $table
* @return string
* @throws Exception
*/
private function builderFrom($table): string
{
if ($table instanceof ActiveQuery) {
$table = '(' . $table->toSql() . ')';
}
return " FROM " . $table;
}
/**
* @param $join
* @return string
*/
#[Pure] private function builderJoin($join): string
{
if (!empty($join)) {
return ' ' . implode(' ', $join);
}
return '';
}
/**
* @param null $select
* @param bool $isCount
* @return string
*/
#[Pure] private function builderSelect($select = NULL, bool $isCount = false): string
{
if ($isCount) {
return "SELECT COUNT(*)";
}
if (empty($select)) {
return "SELECT *";
}
if (is_array($select)) {
return "SELECT " . implode(',', $select);
} else {
return "SELECT " . $select;
}
}
/**
* @param $group
* @return string
*/
private function builderGroup($group): string
{
if (empty($group)) {
return '';
}
return ' GROUP BY ' . $group;
}
/**
* @param $order
* @return string
*/
#[Pure] private function builderOrder($order): string
{
if (!empty($order)) {
return ' ORDER BY ' . implode(',', $order);
} else {
return '';
}
}
/**
* @param ActiveQuery|Query $query
* @param bool $hasLimit
* @return string
*/
#[Pure] private function builderLimit(ActiveQuery|Query $query, bool $hasLimit = true): string
{
if (!is_numeric($query->limit) || $query->limit < 1) {
return "";
}
if ($query->offset !== null && $hasLimit) {
return ' LIMIT ' . $query->offset . ',' . $query->limit;
}
return ' LIMIT ' . $query->limit;
}
/**
* @param $where
* @return string
* @throws Exception
*/
private function where($where): string
{
$_tmp = [];
if (empty($where)) return '';
if (is_string($where)) return $where;
foreach ($where as $key => $value) {
if (is_null($value)) continue;
$_value = $this->resolveCondition($key, $value, $_tmp);
if (empty($_value)) continue;
$_tmp[] = $_value;
}
if (!empty($_tmp)) {
return implode(' AND ', $_tmp);
}
return '';
}
/**
* @param $field
* @param $condition
* @param $_tmp
* @return string
* @throws NotFindClassException
* @throws ReflectionException|Exception
*/
private function resolveCondition($field, $condition, $_tmp): string
{
if (is_string($field)) {
$_value = sprintf('%s = \'%s\'', $field, $condition);
} else if (is_string($condition)) {
$_value = $condition;
} else {
$_value = $this->_arrayMap($condition, $_tmp);
}
return $_value;
}
/**
* @param $condition
* @param $array
* @return string
* @throws Exception
*/
private function _arrayMap($condition, $array): string
{
if (!isset($condition[0])) {
return implode(' AND ', $this->_hashMap($condition));
}
$stroppier = strtoupper($condition[0]);
if (str_contains($stroppier, 'OR')) {
if (!is_string($condition[2])) {
$condition[2] = $this->_hashMap($condition[2]);
}
$builder = Kiri::getDi()->get(OrCondition::class);
$builder->setValue($condition[2]);
$builder->setColumn($condition[1]);
$builder->oldParams = $array;
} else if (isset(ConditionClassMap::$conditionMap[$stroppier])) {
$defaultConfig = ConditionClassMap::$conditionMap[$stroppier];
$class = $defaultConfig['class'];
unset($defaultConfig['class']);
$builder = Kiri::getDi()->make($class, [], $defaultConfig);
$builder->setValue($condition[2]);
$builder->setColumn($condition[1]);
} else {
$builder = Kiri::getDi()->get(HashCondition::class);
$builder->setValue($condition);
}
$array[] = $builder->builder();
return implode(' AND ', $array);
}
/**
* @param $condition
* @return array
*/
private function _hashMap($condition): array
{
$_array = [];
foreach ($condition as $key => $value) {
if (is_null($value)) continue;
$value = is_numeric($value) ? $value : '\'' . $value . '\'';
if (!is_numeric($key)) {
$_array[] = sprintf('%s = %s', $key, $value);
} else {
$_array[] = $value;
}
}
return $_array;
}
}
+45 -47
View File
@@ -12,70 +12,68 @@ namespace Database\Traits;
use Database\ModelInterface;
use Database\Collection;
use Database\Relation;
use Exception;
use Kiri;
/**
* Class HasBase
* @package Database
*
* @include Query
*
* @method first($name)
* @method all($name)
* @method count($name)
*/
abstract class HasBase implements \Database\Traits\Relation
{
/** @var ModelInterface|Collection */
protected Collection|ModelInterface $data;
/** @var ModelInterface|Collection */
protected mixed $data = null;
/**
* @var ModelInterface
*/
protected mixed $model;
protected mixed $value = [];
/**
* @var ModelInterface
*/
protected mixed $model;
/** @var Relation $_relation */
protected Relation $_relation;
protected mixed $value = 0;
/**
* HasBase constructor.
* @param ModelInterface $model
* @param $primaryId
* @param $value
* @param Relation $relation
* @throws Exception
* @param string $name
*/
public function __construct(mixed $model, $primaryId, $value, Relation $relation)
{
if (!class_exists($model)) {
throw new Exception('Model must implement ' . $model);
}
if (!in_array(ModelInterface::class, class_implements($model))) {
throw new Exception('Model must implement ' . $model);
}
if (is_array($value)) {
if (empty($value)) $value = [];
$_model = $model::query()->whereIn($primaryId, $value);
} else {
$_model = $model::query()->where(['t1.' . $primaryId => $value]);
}
$this->_relation = $relation->bindIdentification($model, $_model);
$this->model = $model;
$this->value = $value;
}
public function __construct(public string $name)
{
}
/**
* @param $name
* @return mixed
*/
public function __get($name): mixed
{
if (empty($this->value)) {
return null;
}
return $this->get();
}
/**
* @param string $name
* @param array $arguments
* @return $this|mixed
*/
public function __call(string $name, array $arguments)
{
if ($name !== 'get') {
$relation = Kiri::getDi()->get(Relation::class);
$relation->getQuery($this->name)->$name(...$arguments);
return $this;
} else {
return $this->get();
}
}
/**
* @param string $name
* @return mixed
*/
public function __get(string $name): mixed
{
if ($this->data === null) {
$this->data = $this->get();
}
return $this->data;
}
}
+959 -938
View File
File diff suppressed because it is too large Load Diff
+5
View File
@@ -1,10 +1,15 @@
<?php
declare(strict_types=1);
namespace Database\Traits;
interface Relation
{
/**
* @return mixed
*/
public function get(): mixed;
}
+45 -44
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Database\Traits;
@@ -17,61 +18,61 @@ use JetBrains\PhpStorm\Pure;
class When
{
public ActiveQuery|ISqlBuilder $query;
public ActiveQuery|ISqlBuilder $query;
private array $_condition = [];
private array $_condition = [];
private string $else = '';
private string $else = '';
/**
* CaseWhen constructor.
* @param string $column
* @param ActiveQuery|ISqlBuilder $activeQuery
*/
public function __construct(public string $column, public ActiveQuery|ISqlBuilder $activeQuery)
{
$this->_condition[] = 'CASE ' . $column;
}
/**
* CaseWhen constructor.
* @param string $column
* @param ActiveQuery|ISqlBuilder $activeQuery
*/
public function __construct(public string $column, public ActiveQuery|ISqlBuilder $activeQuery)
{
$this->_condition[] = 'CASE ' . $column;
}
/**
* @param string|int $condition
* @param string $then
* @return $this
* @throws Exception
*/
public function when(string|int $condition, string $then): static
{
$this->_condition[] = sprintf('WHEN %s THEN %s', $condition, $then);
/**
* @param string|int $condition
* @param string $then
* @return $this
* @throws
*/
public function when(string|int $condition, string $then): static
{
$this->_condition[] = sprintf('WHEN %s THEN %s', $condition, $then);
return $this;
}
return $this;
}
/**
* @param string $alias
*/
public function else(string $alias)
{
$this->else = $alias;
}
/**
* @param string $alias
*/
public function else(string $alias): void
{
$this->else = $alias;
}
/**
* @return string
*/
#[Pure] public function end(): string
{
if (empty($this->_condition)) {
return '';
}
$prefix = implode(' ', $this->_condition);
if (!empty($this->else)) {
$prefix .= ' ELSE ' . $this->else;
}
return '(' . $prefix . ' END)';
}
/**
* @return string
*/
#[Pure] public function end(): string
{
if (empty($this->_condition)) {
return '';
}
$prefix = implode(' ', $this->_condition);
if (!empty($this->else)) {
$prefix .= ' ELSE ' . $this->else;
}
return '(' . $prefix . ' END)';
}
}
+2 -3
View File
@@ -9,11 +9,10 @@
],
"license": "MIT",
"require": {
"php": ">=8.0",
"php": ">=8.3",
"ext-json": "*",
"ext-pdo": "*",
"game-worker/kiri-validator": "~v2.0",
"game-worker/kiri-event": "~v2.0"
"game-worker/kiri-pool": "~v1.0"
},
"autoload": {
"psr-4": {