metal-orm 1.0.50 → 1.0.51

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.
package/dist/index.d.cts CHANGED
@@ -92,6 +92,10 @@ declare const col: {
92
92
  * @returns ColumnDef with VARCHAR type
93
93
  */
94
94
  varchar: (length: number) => ColumnDef<"VARCHAR">;
95
+ /**
96
+ * Creates a text column definition
97
+ */
98
+ text: () => ColumnDef<"TEXT">;
95
99
  /**
96
100
  * Creates a fixed precision decimal column definition
97
101
  */
package/dist/index.d.ts CHANGED
@@ -92,6 +92,10 @@ declare const col: {
92
92
  * @returns ColumnDef with VARCHAR type
93
93
  */
94
94
  varchar: (length: number) => ColumnDef<"VARCHAR">;
95
+ /**
96
+ * Creates a text column definition
97
+ */
98
+ text: () => ColumnDef<"TEXT">;
95
99
  /**
96
100
  * Creates a fixed precision decimal column definition
97
101
  */
package/dist/index.js CHANGED
@@ -159,6 +159,10 @@ var col = {
159
159
  * @returns ColumnDef with VARCHAR type
160
160
  */
161
161
  varchar: (length2) => ({ name: "", type: "VARCHAR", args: [length2] }),
162
+ /**
163
+ * Creates a text column definition
164
+ */
165
+ text: () => ({ name: "", type: "TEXT" }),
162
166
  /**
163
167
  * Creates a fixed precision decimal column definition
164
168
  */
@@ -6667,6 +6671,29 @@ var postgresIntrospector = {
6667
6671
  if (!trimmed) return;
6668
6672
  columnComments.set(key, trimmed);
6669
6673
  });
6674
+ const tableCommentRows = await queryRows(
6675
+ ctx.executor,
6676
+ `
6677
+ SELECT
6678
+ ns.nspname AS table_schema,
6679
+ cls.relname AS table_name,
6680
+ pg_catalog.obj_description(cls.oid) AS description
6681
+ FROM pg_catalog.pg_class cls
6682
+ JOIN pg_catalog.pg_namespace ns ON ns.oid = cls.relnamespace
6683
+ WHERE ns.nspname = $1
6684
+ AND cls.relkind IN ('r', 'p')
6685
+ `,
6686
+ [schema]
6687
+ );
6688
+ const tableComments = /* @__PURE__ */ new Map();
6689
+ tableCommentRows.forEach((r) => {
6690
+ if (!shouldIncludeTable(r.table_name, options)) return;
6691
+ if (!r.description) return;
6692
+ const key = `${r.table_schema}.${r.table_name}`;
6693
+ const trimmed = r.description.trim();
6694
+ if (!trimmed) return;
6695
+ tableComments.set(key, trimmed);
6696
+ });
6670
6697
  const qbPk = new SelectQueryBuilder(PgKeyColumnUsage).select({
6671
6698
  table_schema: PgKeyColumnUsage.columns.table_schema,
6672
6699
  table_name: PgKeyColumnUsage.columns.table_name,
@@ -6807,7 +6834,8 @@ var postgresIntrospector = {
6807
6834
  schema: r.table_schema,
6808
6835
  columns: [],
6809
6836
  primaryKey: pkMap.get(key) || [],
6810
- indexes: []
6837
+ indexes: [],
6838
+ comment: tableComments.get(key)
6811
6839
  });
6812
6840
  }
6813
6841
  const cols = tablesByKey.get(key);
@@ -7192,6 +7220,53 @@ var runPragma = async (name, table, alias, columnAliases, ctx) => {
7192
7220
  const query = buildPragmaQuery(name, table, alias, columnAliases);
7193
7221
  return await runSelectNode(query, ctx);
7194
7222
  };
7223
+ var loadSqliteSchemaComments = async (ctx) => {
7224
+ const tableComments = /* @__PURE__ */ new Map();
7225
+ const columnComments = /* @__PURE__ */ new Map();
7226
+ const tableExists = await queryRows(
7227
+ ctx.executor,
7228
+ `SELECT name FROM sqlite_master WHERE type='table' AND name='schema_comments' LIMIT 1`
7229
+ );
7230
+ if (!tableExists.length) {
7231
+ return { tableComments, columnComments };
7232
+ }
7233
+ const commentRows = await queryRows(
7234
+ ctx.executor,
7235
+ `SELECT object_type, schema_name, table_name, column_name, comment FROM schema_comments`
7236
+ );
7237
+ for (const row of commentRows) {
7238
+ const objectType = typeof row.object_type === "string" ? row.object_type.toLowerCase() : "";
7239
+ const tableName = typeof row.table_name === "string" ? row.table_name : "";
7240
+ if (!tableName) continue;
7241
+ const columnName = typeof row.column_name === "string" ? row.column_name : "";
7242
+ const schemaName = typeof row.schema_name === "string" ? row.schema_name : "";
7243
+ const rawComment = row.comment;
7244
+ if (rawComment == null) continue;
7245
+ const commentText = String(rawComment).trim();
7246
+ if (!commentText) continue;
7247
+ const addTableComment = () => {
7248
+ tableComments.set(tableName, commentText);
7249
+ if (schemaName) {
7250
+ tableComments.set(`${schemaName}.${tableName}`, commentText);
7251
+ }
7252
+ };
7253
+ const addColumnComment = () => {
7254
+ columnComments.set(`${tableName}.${columnName}`, commentText);
7255
+ if (schemaName) {
7256
+ columnComments.set(`${schemaName}.${tableName}.${columnName}`, commentText);
7257
+ }
7258
+ };
7259
+ if (objectType === "table") {
7260
+ addTableComment();
7261
+ } else if (objectType === "column" && columnName) {
7262
+ addColumnComment();
7263
+ }
7264
+ }
7265
+ return {
7266
+ tableComments,
7267
+ columnComments
7268
+ };
7269
+ };
7195
7270
  var sqliteIntrospector = {
7196
7271
  async introspect(ctx, options) {
7197
7272
  const alias = "sqlite_master";
@@ -7205,6 +7280,7 @@ var sqliteIntrospector = {
7205
7280
  notLike(columnNode2(alias, "name"), "sqlite_%")
7206
7281
  )
7207
7282
  };
7283
+ const { tableComments, columnComments } = await loadSqliteSchemaComments(ctx);
7208
7284
  const tableRows = await runSelectNode(tablesQuery, ctx);
7209
7285
  const tables = [];
7210
7286
  for (const row of tableRows) {
@@ -7231,15 +7307,26 @@ var sqliteIntrospector = {
7231
7307
  ["seq", "name", "unique"],
7232
7308
  ctx
7233
7309
  );
7234
- const tableEntry = { name: tableName, columns: [], primaryKey: [], indexes: [] };
7310
+ const tableEntry = {
7311
+ name: tableName,
7312
+ columns: [],
7313
+ primaryKey: [],
7314
+ indexes: [],
7315
+ comment: tableComments.get(tableName)
7316
+ };
7235
7317
  tableInfo.forEach((info) => {
7236
- tableEntry.columns.push({
7318
+ const column = {
7237
7319
  name: info.name,
7238
7320
  type: info.type,
7239
7321
  notNull: info.notnull === 1,
7240
7322
  default: info.dflt_value ?? void 0,
7241
7323
  autoIncrement: false
7242
- });
7324
+ };
7325
+ const columnComment = columnComments.get(`${tableName}.${info.name}`);
7326
+ if (columnComment) {
7327
+ column.comment = columnComment;
7328
+ }
7329
+ tableEntry.columns.push(column);
7243
7330
  if (info.pk && info.pk > 0) {
7244
7331
  tableEntry.primaryKey = tableEntry.primaryKey || [];
7245
7332
  tableEntry.primaryKey.push(info.name);
@@ -7511,6 +7598,60 @@ var mssqlIntrospector = {
7511
7598
  async introspect(ctx, options) {
7512
7599
  const schema = options.schema;
7513
7600
  const schemaCondition = schema ? eq(columnNode3("sch", "name"), schema) : void 0;
7601
+ const schemaFilter = schema ? "AND sch.name = @p1" : "";
7602
+ const schemaParams = schema ? [schema] : [];
7603
+ const tableCommentRows = await queryRows(
7604
+ ctx.executor,
7605
+ `
7606
+ SELECT
7607
+ sch.name AS table_schema,
7608
+ t.name AS table_name,
7609
+ CONVERT(nvarchar(4000), ep.value) AS comment
7610
+ FROM sys.extended_properties ep
7611
+ JOIN sys.tables t ON t.object_id = ep.major_id
7612
+ JOIN sys.schemas sch ON sch.schema_id = t.schema_id
7613
+ WHERE ep.class = 1
7614
+ AND ep.minor_id = 0
7615
+ AND ep.name = 'MS_Description'
7616
+ ${schemaFilter}
7617
+ `,
7618
+ schemaParams
7619
+ );
7620
+ const columnCommentRows = await queryRows(
7621
+ ctx.executor,
7622
+ `
7623
+ SELECT
7624
+ sch.name AS table_schema,
7625
+ t.name AS table_name,
7626
+ col.name AS column_name,
7627
+ CONVERT(nvarchar(4000), ep.value) AS comment
7628
+ FROM sys.extended_properties ep
7629
+ JOIN sys.columns col ON col.object_id = ep.major_id AND col.column_id = ep.minor_id
7630
+ JOIN sys.tables t ON t.object_id = col.object_id
7631
+ JOIN sys.schemas sch ON sch.schema_id = t.schema_id
7632
+ WHERE ep.class = 1
7633
+ AND ep.minor_id > 0
7634
+ AND ep.name = 'MS_Description'
7635
+ ${schemaFilter}
7636
+ `,
7637
+ schemaParams
7638
+ );
7639
+ const tableComments = /* @__PURE__ */ new Map();
7640
+ tableCommentRows.forEach((r) => {
7641
+ if (!shouldIncludeTable(r.table_name, options)) return;
7642
+ if (!r.comment) return;
7643
+ const trimmed = r.comment.trim();
7644
+ if (!trimmed) return;
7645
+ tableComments.set(`${r.table_schema}.${r.table_name}`, trimmed);
7646
+ });
7647
+ const columnComments = /* @__PURE__ */ new Map();
7648
+ columnCommentRows.forEach((r) => {
7649
+ if (!shouldIncludeTable(r.table_name, options)) return;
7650
+ if (!r.comment) return;
7651
+ const trimmed = r.comment.trim();
7652
+ if (!trimmed) return;
7653
+ columnComments.set(`${r.table_schema}.${r.table_name}.${r.column_name}`, trimmed);
7654
+ });
7514
7655
  const dataTypeExpression = buildMssqlDataType(
7515
7656
  { table: "ty", name: "name" },
7516
7657
  { table: "c", name: "max_length" },
@@ -7816,7 +7957,8 @@ var mssqlIntrospector = {
7816
7957
  schema: r.table_schema,
7817
7958
  columns: [],
7818
7959
  primaryKey: pkMap.get(key) || [],
7819
- indexes: []
7960
+ indexes: [],
7961
+ comment: tableComments.get(key)
7820
7962
  });
7821
7963
  }
7822
7964
  const table = tablesByKey.get(key);
@@ -7827,6 +7969,10 @@ var mssqlIntrospector = {
7827
7969
  default: r.column_default ?? void 0,
7828
7970
  autoIncrement: !!r.is_identity
7829
7971
  };
7972
+ const columnComment = columnComments.get(`${key}.${r.column_name}`);
7973
+ if (columnComment) {
7974
+ column.comment = columnComment;
7975
+ }
7830
7976
  const fk = fkMap.get(`${key}.${r.column_name}`)?.[0];
7831
7977
  if (fk) {
7832
7978
  column.references = {