create-prisma-php-app 1.17.13 → 1.17.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -254,7 +254,7 @@ abstract class Utility
254
254
  $sqlConditions[] = "$fieldQuoted != ''";
255
255
  } else {
256
256
  $validatedValue = Validator::string($val);
257
- $likeOperator = $condition === 'contains' ? (($dbType == 'pgsql' || $dbType == 'sqlite') ? 'ILIKE' : 'LIKE') : '=';
257
+ $likeOperator = $condition === 'contains' ? ($dbType == 'pgsql' ? 'ILIKE' : 'LIKE') : '=';
258
258
  if ($condition === 'startsWith') $validatedValue .= '%';
259
259
  if ($condition === 'endsWith') $validatedValue = '%' . $validatedValue;
260
260
  if ($condition === 'contains') $validatedValue = '%' . $validatedValue . '%';
@@ -266,7 +266,15 @@ abstract class Utility
266
266
  case 'gte':
267
267
  case 'lt':
268
268
  case 'lte':
269
- $validatedValue = is_float($val) ? Validator::float($val) : Validator::int($val);
269
+ if (is_float($val)) {
270
+ $validatedValue = Validator::float($val);
271
+ } elseif (is_int($val)) {
272
+ $validatedValue = Validator::int($val);
273
+ } elseif (strtotime($val) !== false) {
274
+ $validatedValue = date('Y-m-d H:i:s', strtotime($val));
275
+ } else {
276
+ $validatedValue = Validator::string($val);
277
+ }
270
278
  $operator = $condition === 'gt' ? '>' : ($condition === 'gte' ? '>=' : ($condition === 'lt' ? '<' : '<='));
271
279
  $sqlConditions[] = "$fieldQuoted $operator $bindingKey";
272
280
  $bindings[$bindingKey] = $validatedValue;
@@ -318,4 +326,33 @@ abstract class Utility
318
326
  }
319
327
  }
320
328
  }
329
+
330
+ public static function queryOptions(array $criteria, string &$sql)
331
+ {
332
+ if (isset($criteria['orderBy'])) {
333
+ $orderByParts = [];
334
+
335
+ // Check if orderBy is an associative array with directions or a list of columns
336
+ if (array_values($criteria['orderBy']) === $criteria['orderBy']) {
337
+ // If it's a list of columns, default to 'asc'
338
+ foreach ($criteria['orderBy'] as $column) {
339
+ $orderByParts[] = "$column asc";
340
+ }
341
+ } else {
342
+ // If it's an associative array with directions
343
+ foreach ($criteria['orderBy'] as $column => $direction) {
344
+ $direction = strtolower($direction) === 'desc' ? 'desc' : 'asc';
345
+ $orderByParts[] = "$column $direction";
346
+ }
347
+ }
348
+
349
+ $sql .= " ORDER BY " . implode(', ', $orderByParts);
350
+ }
351
+ if (isset($criteria['take'])) {
352
+ $sql .= " LIMIT " . intval($criteria['take']);
353
+ }
354
+ if (isset($criteria['skip'])) {
355
+ $sql .= " OFFSET " . intval($criteria['skip']);
356
+ }
357
+ }
321
358
  }
@@ -71,6 +71,17 @@ class Validator
71
71
  return preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/', $value) ? $value : null;
72
72
  }
73
73
 
74
+ /**
75
+ * Validate a CUID.
76
+ *
77
+ * @param mixed $value The value to validate.
78
+ * @return string|null The valid CUID or null if invalid.
79
+ */
80
+ public static function cuid($value): ?string
81
+ {
82
+ return preg_match('/^c[0-9a-z]{8,}$/', $value) ? $value : null;
83
+ }
84
+
74
85
  /**
75
86
  * Validate a size string (e.g., "10MB").
76
87
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "1.17.13",
3
+ "version": "1.17.15",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",