@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
90 lines (86 loc) • 3.52 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/field.ts
var field_exports = {};
__export(field_exports, {
fieldParser: () => fieldParser
});
module.exports = __toCommonJS(field_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/field.ts
var fieldParser = (0, import_databases.adapterFieldParser)({
// eslint-disable-next-line ts/require-await
translate: /* @__PURE__ */ __name(async (args) => {
if (args.customAttributes.type) return getBuilderArgs({
type: args.customAttributes.type,
databaseName: args.field.databaseName,
args: args.customAttributes.args
}, (defaultBuilderArgs) => defaultBuilderArgs)(args.customAttributes.args, args.customAttributes.options);
if (args.field.dbIndex) {
args.lazyEvaluate({
type: "index",
indexAttributes: {
modelName: args.modelName,
fieldName: args.field.fieldName,
databaseName: args.field.databaseName,
unique: args.field.unique
}
});
}
const fieldData = {
fieldName: args.field.fieldName,
primaryKey: args.field.primaryKey,
unique: args.field.unique,
nullable: args.field.allowNull,
dbIndex: args.field.dbIndex,
default: args.field.defaultValue,
autoincrement: args.field.isAuto,
databaseName: args.field.databaseName,
custom: args.customAttributes
};
return fieldData;
}, "translate")
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
fieldParser
});