@shotleybuilder/svelte-gridlite-kit 0.3.0 → 0.3.1

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.
@@ -1,5 +1,5 @@
1
1
  <script>import { onMount, onDestroy } from "svelte";
2
- import { introspectTable, getColumnNames } from "./query/schema.js";
2
+ import { introspectTable, getColumnNames, mapOidToDataType } from "./query/schema.js";
3
3
  import {
4
4
  buildQuery,
5
5
  buildCountQuery,
@@ -197,6 +197,16 @@ async function rebuildQuery() {
197
197
  store = createLiveQueryStore(db, sql, params);
198
198
  store.subscribe((state) => {
199
199
  storeState = state;
200
+ if (query && columns.length === 0 && state.fields.length > 0) {
201
+ columns = state.fields.map((f) => ({
202
+ name: f.name,
203
+ dataType: mapOidToDataType(f.dataTypeID),
204
+ postgresType: "unknown",
205
+ nullable: true,
206
+ hasDefault: false
207
+ }));
208
+ allowedColumns = columns.map((c) => c.name);
209
+ }
200
210
  });
201
211
  }
202
212
  function cleanAgg(g) {
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ export { default as RowDetailModal } from "./components/RowDetailModal.svelte";
11
11
  export type { GridLiteProps, GridConfig, GridFeatures, GridState, ColumnConfig, ColumnDataType, ColumnMetadata, FilterCondition, FilterOperator, FilterLogic, SortConfig, GroupConfig, AggregationConfig, AggregateFunction, ViewPreset, ClassNameMap, RowHeight, ColumnSpacing, ParameterizedQuery, ToolbarLayout, } from "./types.js";
12
12
  export { quoteIdentifier, buildWhereClause, buildOrderByClause, buildGroupByClause, buildPaginationClause, buildGlobalSearchClause, buildGroupSummaryQuery, buildGroupCountQuery, buildGroupDetailQuery, buildQuery, buildCountQuery, } from "./query/builder.js";
13
13
  export type { QueryOptions, GroupSummaryOptions, GroupDetailOptions, } from "./query/builder.js";
14
- export { mapPostgresType, introspectTable, getColumnNames, } from "./query/schema.js";
14
+ export { mapPostgresType, mapOidToDataType, introspectTable, getColumnNames, } from "./query/schema.js";
15
15
  export { createLiveQueryStore, createLiveQueryStoreFromQuery, } from "./query/live.js";
16
16
  export type { LiveQueryState, LiveQueryStore, PGliteWithLive, } from "./query/live.js";
17
17
  export { runMigrations, getLatestVersion, isMigrated, } from "./state/migrations.js";
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ export { default as RowDetailModal } from "./components/RowDetailModal.svelte";
14
14
  // Query builder
15
15
  export { quoteIdentifier, buildWhereClause, buildOrderByClause, buildGroupByClause, buildPaginationClause, buildGlobalSearchClause, buildGroupSummaryQuery, buildGroupCountQuery, buildGroupDetailQuery, buildQuery, buildCountQuery, } from "./query/builder.js";
16
16
  // Schema introspection
17
- export { mapPostgresType, introspectTable, getColumnNames, } from "./query/schema.js";
17
+ export { mapPostgresType, mapOidToDataType, introspectTable, getColumnNames, } from "./query/schema.js";
18
18
  // Live query store
19
19
  export { createLiveQueryStore, createLiveQueryStoreFromQuery, } from "./query/live.js";
20
20
  // State persistence — migrations
@@ -5,13 +5,18 @@
5
5
  * and nullability for a given table. Maps Postgres data types to
6
6
  * GridLite's ColumnDataType for filter operator selection and UI rendering.
7
7
  */
8
- import type { PGlite } from '@electric-sql/pglite';
9
- import type { ColumnDataType, ColumnMetadata } from '../types.js';
8
+ import type { PGlite } from "@electric-sql/pglite";
9
+ import type { ColumnDataType, ColumnMetadata } from "../types.js";
10
10
  /**
11
11
  * Map a Postgres data_type string (from information_schema.columns)
12
12
  * to a GridLite ColumnDataType.
13
13
  */
14
14
  export declare function mapPostgresType(postgresType: string): ColumnDataType;
15
+ /**
16
+ * Map a Postgres type OID to a GridLite ColumnDataType.
17
+ * Returns 'text' for unrecognized OIDs.
18
+ */
19
+ export declare function mapOidToDataType(oid: number): ColumnDataType;
15
20
  /**
16
21
  * Introspect a table's schema using information_schema.columns.
17
22
  *
@@ -13,34 +13,69 @@
13
13
  export function mapPostgresType(postgresType) {
14
14
  const t = postgresType.toLowerCase();
15
15
  // Numeric types
16
- if (t === 'integer' ||
17
- t === 'bigint' ||
18
- t === 'smallint' ||
19
- t === 'numeric' ||
20
- t === 'decimal' ||
21
- t === 'real' ||
22
- t === 'double precision' ||
23
- t === 'serial' ||
24
- t === 'bigserial' ||
25
- t === 'smallserial' ||
26
- t === 'money') {
27
- return 'number';
16
+ if (t === "integer" ||
17
+ t === "bigint" ||
18
+ t === "smallint" ||
19
+ t === "numeric" ||
20
+ t === "decimal" ||
21
+ t === "real" ||
22
+ t === "double precision" ||
23
+ t === "serial" ||
24
+ t === "bigserial" ||
25
+ t === "smallserial" ||
26
+ t === "money") {
27
+ return "number";
28
28
  }
29
29
  // Date/time types
30
- if (t === 'date' ||
31
- t === 'timestamp without time zone' ||
32
- t === 'timestamp with time zone' ||
33
- t === 'time without time zone' ||
34
- t === 'time with time zone' ||
35
- t === 'interval') {
36
- return 'date';
30
+ if (t === "date" ||
31
+ t === "timestamp without time zone" ||
32
+ t === "timestamp with time zone" ||
33
+ t === "time without time zone" ||
34
+ t === "time with time zone" ||
35
+ t === "interval") {
36
+ return "date";
37
37
  }
38
38
  // Boolean
39
- if (t === 'boolean') {
40
- return 'boolean';
39
+ if (t === "boolean") {
40
+ return "boolean";
41
41
  }
42
42
  // Everything else is text (varchar, char, text, json, jsonb, uuid, etc.)
43
- return 'text';
43
+ return "text";
44
+ }
45
+ // ─── OID → ColumnDataType Mapping ───────────────────────────────────────────
46
+ /**
47
+ * Map a Postgres type OID (from query result fields) to a GridLite ColumnDataType.
48
+ * Used when introspecting columns from raw query results rather than information_schema.
49
+ *
50
+ * Common OIDs from the Postgres catalog (pg_type):
51
+ * https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.dat
52
+ */
53
+ const OID_MAP = {
54
+ // Boolean
55
+ 16: "boolean",
56
+ // Numeric
57
+ 20: "number", // int8 / bigint
58
+ 21: "number", // int2 / smallint
59
+ 23: "number", // int4 / integer
60
+ 26: "number", // oid
61
+ 700: "number", // float4 / real
62
+ 701: "number", // float8 / double precision
63
+ 790: "number", // money
64
+ 1700: "number", // numeric / decimal
65
+ // Date/time
66
+ 1082: "date", // date
67
+ 1083: "date", // time
68
+ 1114: "date", // timestamp without time zone
69
+ 1184: "date", // timestamp with time zone
70
+ 1186: "date", // interval
71
+ 1266: "date", // time with time zone
72
+ };
73
+ /**
74
+ * Map a Postgres type OID to a GridLite ColumnDataType.
75
+ * Returns 'text' for unrecognized OIDs.
76
+ */
77
+ export function mapOidToDataType(oid) {
78
+ return OID_MAP[oid] ?? "text";
44
79
  }
45
80
  /**
46
81
  * Introspect a table's schema using information_schema.columns.
@@ -52,7 +87,7 @@ export function mapPostgresType(postgresType) {
52
87
  * @param tableName - The table to introspect
53
88
  * @param schema - The schema to search (defaults to 'public')
54
89
  */
55
- export async function introspectTable(db, tableName, schema = 'public') {
90
+ export async function introspectTable(db, tableName, schema = "public") {
56
91
  const result = await db.query(`SELECT column_name, data_type, is_nullable, column_default
57
92
  FROM information_schema.columns
58
93
  WHERE table_name = $1 AND table_schema = $2
@@ -61,15 +96,15 @@ export async function introspectTable(db, tableName, schema = 'public') {
61
96
  name: row.column_name,
62
97
  dataType: mapPostgresType(row.data_type),
63
98
  postgresType: row.data_type,
64
- nullable: row.is_nullable === 'YES',
65
- hasDefault: row.column_default !== null
99
+ nullable: row.is_nullable === "YES",
100
+ hasDefault: row.column_default !== null,
66
101
  }));
67
102
  }
68
103
  /**
69
104
  * Get the list of column names for a table.
70
105
  * Useful for the query builder's allowedColumns parameter.
71
106
  */
72
- export async function getColumnNames(db, tableName, schema = 'public') {
107
+ export async function getColumnNames(db, tableName, schema = "public") {
73
108
  const columns = await introspectTable(db, tableName, schema);
74
109
  return columns.map((c) => c.name);
75
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shotleybuilder/svelte-gridlite-kit",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A SQL-native data grid component for Svelte and SvelteKit, powered by PGLite",
5
5
  "author": "Sertantai",
6
6
  "license": "MIT",