forge-sql-orm
Version:
Drizzle ORM integration for Atlassian @forge/sql. Provides a custom driver, schema migration, two levels of caching (local and global via @forge/kvs), optimistic locking, and query analysis.
77 lines • 2.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.forgeTimeString = exports.forgeDateString = exports.forgeTimestampString = exports.forgeDateTimeString = void 0;
const mysql_core_1 = require("drizzle-orm/mysql-core");
const sqlUtils_1 = require("../utils/sqlUtils");
/**
* Custom type for MySQL datetime fields.
* Handles conversion between JavaScript Date objects and MySQL datetime strings.
*
* @type {CustomType}
*/
exports.forgeDateTimeString = (0, mysql_core_1.customType)({
dataType() {
return "datetime";
},
toDriver(value) {
return (0, sqlUtils_1.formatDateTime)(value, "yyyy-MM-dd' 'HH:mm:ss.SSS", false);
},
fromDriver(value) {
const format = "yyyy-MM-dd' 'HH:mm:ss.SSS";
return (0, sqlUtils_1.parseDateTime)(value, format);
},
});
/**
* Custom type for MySQL timestamp fields.
* Handles conversion between JavaScript Date objects and MySQL timestamp strings.
*
* @type {CustomType}
*/
exports.forgeTimestampString = (0, mysql_core_1.customType)({
dataType() {
return "timestamp";
},
toDriver(value) {
return (0, sqlUtils_1.formatDateTime)(value, "yyyy-MM-dd' 'HH:mm:ss.SSS", true);
},
fromDriver(value) {
const format = "yyyy-MM-dd' 'HH:mm:ss.SSS";
return (0, sqlUtils_1.parseDateTime)(value, format);
},
});
/**
* Custom type for MySQL date fields.
* Handles conversion between JavaScript Date objects and MySQL date strings.
*
* @type {CustomType}
*/
exports.forgeDateString = (0, mysql_core_1.customType)({
dataType() {
return "date";
},
toDriver(value) {
return (0, sqlUtils_1.formatDateTime)(value, "yyyy-MM-dd", false);
},
fromDriver(value) {
const format = "yyyy-MM-dd";
return (0, sqlUtils_1.parseDateTime)(value, format);
},
});
/**
* Custom type for MySQL time fields.
* Handles conversion between JavaScript Date objects and MySQL time strings.
*
* @type {CustomType}
*/
exports.forgeTimeString = (0, mysql_core_1.customType)({
dataType() {
return "time";
},
toDriver(value) {
return (0, sqlUtils_1.formatDateTime)(value, "HH:mm:ss.SSS", false);
},
fromDriver(value) {
return (0, sqlUtils_1.parseDateTime)(value, "HH:mm:ss.SSS");
},
});
//# sourceMappingURL=ForgeSQLQueryBuilder.js.map