You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/js-lang-overview.md
+21-17Lines changed: 21 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -53,20 +53,24 @@ When the data converts to a JS string, it automatically changes from the SQL par
53
53
54
54
## Convert JS data types to SQL
55
55
56
-
The target SQL data type defines how the system converts values. The system typically converts a JS value to one of the basic types, such as string, integer, or double, depending on the SQL data type. After the conversion, the system stores the result in the SQL parameter or return value. This step can fail if the value is too large or has an incorrect format, which will cause an error. During the process, JS strings automatically convert from `utf8mb4` to the character set of the SQL parameter.
57
-
58
-
JS `null` and `undefined` values always convert to SQL `NULL` values for the target SQL type.
59
-
60
-
| Target SQL data type | Rules for converting JS value | Example |
| FLOAT, DOUBLE | Stored as doubles for Numbers, converted to strings for other values | 3.14 → 3.14, "3.14" → "3.14" |
65
-
| BIT | Converted to SQL BIT type | 1 → BIT(1) |
66
-
| BigInt | For BigInt values: stored as integers. For other values: converted to Number then stored. Invalid Number conversions cause errors | 9007n → 9007, "123" → 123 |
67
-
| TIME, DATE, TIMESTAMP, DATETIME | Converted to strings | Date() → "2024-01-30" |
68
-
| CHAR, VARCHAR, TINYTEXT, TEXT, MEDIUMTEXT, ENUM | Converted to strings with charset conversion if needed | "hello" → "hello" |
69
-
| BINARY, VARBINARY, TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB | ArrayBuffer/ArrayBufferView: stored directly. Other values: converted to strings | buffer → binary data |
70
-
| SET | Numbers: stored as integers or doubles. BigInt: stored as integers. Others: converted to strings with charset conversion if needed | 1 → 1, "value" → "value" |
71
-
| GEOMETRY | ArrayBuffer/ArrayBufferView: stored as binary if valid GEOMETRY. Other values: error | valid buffer → GEOMETRY |
72
-
| JSON | Converted to JSON string using JSON.stringify() | {key: "value"} → "{"key":"value"}" |
56
+
The system uses the target SQL data type to determine how to convert each value. It typically converts a JS value into a basic type—such as a string, integer, or double—based on the specified SQL type. Once converted, the system stores the result in the corresponding SQL parameter or return value.
57
+
58
+
If a value exceeds allowed limits or uses an unsupported format, the conversion fails and triggers an error. During this process, the system automatically converts JS strings from the utf8mb4 encoding to the character set defined by the SQL parameter.
59
+
60
+
The system always maps JS null and undefined values to SQL NULL, regardless of the target SQL type.
61
+
62
+
### JS to SQL type conversion rules
63
+
64
+
| Target SQL Data Type | Conversion Rules | Explanation | Example |
|`BOOLEAN`, `TINYINT`, `SHORTINT`, `MEDIUMINT`, `INT`, `BIGINT`| (Version 8.4.5) - Numbers: stored as integers<br>- Booleans: `true` → `1`, `false` → `0`<br>- BigInts: stored as integers when possible<br>- Other types: converted to strings first | Preserves native numeric forms where possible; other values default to string representation<br>(Version 8.4.4) - JS Integers/Numbers: integers stored as-is, BigInts attempted as integers, others as strings.) |`42` → `42`<br>`3.14` → `"3.14"`<br>`true` → `"true"`|
67
+
|`DECIMAL`| - All values converted to strings<br>- **Booleans: converted to `0`/`1`, then stored as doubles | Supports precision formatting; special handling ensures Booleans fit numeric context |`123.45` → `"123.45"`<br>`true` → `1.0`|
68
+
|`FLOAT`, `DOUBLE`| - Numbers: stored as doubles<br>- (Version 8.4.5) - Booleans: converted to `0`/`1`, then stored as doubles<br>- Others: converted to strings | Treats numeric and Boolean inputs consistently using floating-point representation |`3.14` → `3.14`<br>`true` → `1.0`<br>`"3.14"` → `"3.14"`|
69
+
|`BIT`| Converted to SQL BIT type | Only binary-compatible values allowed |`1` → `BIT(1)`|
70
+
|`BIGINT`| - BigInts: stored directly<br>- Others: converted to Numbers, then stored<br>- Invalid conversions trigger errors | Ensures only safe numeric coercions persist |`9007n` → `9007`<br>`"123"` → `123`|
71
+
|`TIME`, `DATE`, `TIMESTAMP`, `DATETIME`| All values converted to strings | Usually expects ISO date formats or equivalents |`Date()` → `"2024-01-30"`|
72
+
|`CHAR`, `VARCHAR`, `TEXT`, etc. | All values converted to strings<br>Charset conversion from `utf8mb4` if needed | Supports text types with encoding fallback |`"hello"` → `"hello"`|
73
+
|`BINARY`, `VARBINARY`, `BLOB`, etc. | - `ArrayBuffer`/`View`: stored directly<br>- Others: converted to strings | Binary data must be explicitly wrapped; others fallback to string |`buffer` → binary |
74
+
|`SET`| - Numbers: stored as integers/doubles<br>- BigInts: stored as integers<br>- Others: converted to strings with charset conversion if needed | Tries native storage before falling back to strings |`1` → `1`<br>`"value"` → `"value"`|
75
+
|`GEOMETRY`| - Valid `ArrayBuffer`/`View`: stored as binary<br>- Others: cause an error | Enforces format rules to maintain spatial integrity | valid buffer → `GEOMETRY`|
76
+
|`JSON`| Converted using `JSON.stringify()`| Converts objects or arrays to serialized strings |`{key: "value"}` → `"{"key":"value"}"`|
0 commit comments