@palmares/drizzle-engine
Version:
This is the engine that wraps the hole drizzle interface in a way palmares can understand and have full control of
86 lines (82 loc) • 3.28 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/fields/text.ts
var text_exports = {};
__export(text_exports, {
textFieldParser: () => textFieldParser
});
module.exports = __toCommonJS(text_exports);
var import_databases = require("@palmares/databases");
// src/fields/utils.ts
function getBuilderArgs(builder, callback) {
const defaultOptions = callback([]);
return (customAttributesArgs, customAttributesOptions) => {
const customAttributesDefined = new Set(Object.keys(customAttributesOptions || {}));
const builderArgs = Object.entries(customAttributesOptions || {}).map(([method, args]) => {
return [
method,
args.map((arg) => typeof arg === "object" ? JSON.stringify(arg) : arg.toString()).join(", ")
];
});
for (const [method, args] of defaultOptions) if (!customAttributesDefined.has(method)) builderArgs.push([
method,
args
]);
const builderArguments = builderArgs.map(([method, args]) => {
return (args || []).length > 0 ? `.${method}(${args})` : `.${method}()`;
}).join("");
return `${builder.withoutD ? "" : "d."}${builder.type}('${builder.databaseName}'${customAttributesArgs !== void 0 || builder.args ? `, ${customAttributesArgs !== void 0 ? JSON.stringify(customAttributesArgs) : builder.args}` : ""})${builderArguments}`;
};
}
__name(getBuilderArgs, "getBuilderArgs");
// src/fields/text.ts
var textFieldParser = (0, import_databases.adapterTextFieldParser)({
translate: /* @__PURE__ */ __name(async (args) => {
const defaultOptions = await args.fieldParser.translate(args);
const field = args.field;
return getBuilderArgs({
type: "text",
databaseName: field.databaseName,
args: void 0
}, (defaultBuilderArgs) => {
if (defaultOptions.primaryKey) defaultBuilderArgs.push([
"primaryKey",
""
]);
if (defaultOptions.default) defaultBuilderArgs.push([
"default",
`"${defaultOptions.default}"`
]);
if (defaultOptions.nullable !== true) defaultBuilderArgs.push([
"notNull",
""
]);
if (defaultOptions.unique) defaultBuilderArgs.push([
"unique",
""
]);
return defaultBuilderArgs;
})(args.customAttributes.args, args.customAttributes.options);
}, "translate")
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
textFieldParser
});