@duckdb/react-duckdb 1.13.1-dev267.0 → 1.13.1-dev273.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duckdb/react-duckdb",
3
- "version": "1.13.1-dev267.0",
3
+ "version": "1.13.1-dev273.0",
4
4
  "description": "React components for DuckDB-Wasm",
5
5
  "license": "MPL-2.0",
6
6
  "repository": {
package/src/index.ts CHANGED
@@ -1,7 +1,4 @@
1
1
  export * from './connection_provider';
2
2
  export * from './database_provider';
3
3
  export * from './platform_provider';
4
- export * from './table_schema';
5
- export * from './table_schema_provider';
6
- export * from './epoch_contexts';
7
4
  export * from './resolvable';
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
-
3
- export const TABLE_SCHEMA_EPOCH = React.createContext<number | null>(null);
4
- export const useTableSchemaEpoch = (): number | null => React.useContext(TABLE_SCHEMA_EPOCH);
5
-
6
- export const TABLE_DATA_EPOCH = React.createContext<number | null>(null);
7
- export const useTableDataEpoch = (): number | null => React.useContext(TABLE_DATA_EPOCH);
@@ -1,117 +0,0 @@
1
- import * as arrow from 'apache-arrow';
2
- import * as duckdb from '@duckdb/duckdb-wasm';
3
-
4
- /// A column group
5
- export interface TableSchemaColumnGroup {
6
- /// The group title
7
- title: string;
8
- /// The begin of the column span
9
- spanBegin: number;
10
- /// The size of the column span
11
- spanSize: number;
12
- }
13
-
14
- /// A table metadatStorea
15
- export interface TableSchema {
16
- /// The table schema
17
- readonly tableSchema: string;
18
- /// The table name
19
- readonly tableName: string;
20
-
21
- /// The column names
22
- readonly columnNames: string[];
23
- /// The column name indices
24
- readonly columnNameMapping: Map<string, number>;
25
- /// The column types
26
- readonly columnTypes: arrow.DataType[];
27
- /// The number of data columns.
28
- /// Allows to append compute metadata columns that are not rendered in the table viewer.
29
- readonly dataColumns: number;
30
-
31
- /// The column aliases (if any)
32
- readonly columnAliases: (string | null)[];
33
- /// The column grouping sets (if any)
34
- readonly columnGroupingSets: TableSchemaColumnGroup[][];
35
- /// The row grouping sets (if any)
36
- readonly rowGroupingSets: number[][];
37
- }
38
-
39
- /// Get raw qualified name
40
- export function getQualifiedNameRaw(schema: string, name: string) {
41
- return `${schema || 'main'}.${name}`;
42
- }
43
- /// Get qualified name
44
- export function getQualifiedName(table: TableSchema) {
45
- return `${table.tableSchema}.${table.tableName}`;
46
- }
47
-
48
- /// Collect table info
49
- export async function collectTableSchema(
50
- conn: duckdb.AsyncDuckDBConnection,
51
- info: Partial<TableSchema> & { tableSchema?: string; tableName: string },
52
- ): Promise<TableSchema> {
53
- // Use DESCRIBE to find all column types
54
- const columnNames: string[] = [];
55
- const columnNameMapping: Map<string, number> = new Map();
56
- const columnTypes: arrow.DataType[] = [];
57
- const describe = await conn.query<{ Field: arrow.Utf8; Type: arrow.Utf8 }>(
58
- `DESCRIBE ${info.tableSchema || 'main'}.${info.tableName}`,
59
- );
60
- let column = 0;
61
- for (const row of describe) {
62
- columnNames.push(row!.Field!);
63
- columnNameMapping.set(row!.Field!, column++);
64
- const mapType = (type: string): arrow.DataType => {
65
- switch (type) {
66
- case 'BOOLEAN':
67
- return new arrow.Bool();
68
- case 'TINYINT':
69
- return new arrow.Int8();
70
- case 'SMALLINT':
71
- return new arrow.Int16();
72
- case 'INTEGER':
73
- return new arrow.Int32();
74
- case 'BIGINT':
75
- return new arrow.Int64();
76
- case 'UTINYINT':
77
- return new arrow.Uint8();
78
- case 'USMALLINT':
79
- return new arrow.Uint16();
80
- case 'UINTEGER':
81
- return new arrow.Uint32();
82
- case 'UBIGINT':
83
- return new arrow.Uint64();
84
- case 'FLOAT':
85
- return new arrow.Float32();
86
- case 'HUGEINT':
87
- return new arrow.Decimal(32, 0);
88
- case 'DOUBLE':
89
- return new arrow.Float64();
90
- case 'VARCHAR':
91
- return new arrow.Utf8();
92
- case 'DATE':
93
- return new arrow.DateDay();
94
- case 'TIME':
95
- return new arrow.Time(arrow.TimeUnit.MILLISECOND, 32);
96
- case 'TIMESTAMP':
97
- return new arrow.TimeNanosecond();
98
- default:
99
- return new arrow.Null();
100
- }
101
- };
102
- columnTypes.push(mapType(row!.Type!));
103
- }
104
- const table: TableSchema = {
105
- ...info,
106
- tableSchema: info.tableSchema || 'main',
107
- columnNames,
108
- columnTypes,
109
- dataColumns: columnTypes.length,
110
- columnNameMapping,
111
- columnAliases: [],
112
- columnGroupingSets: [],
113
- rowGroupingSets: [],
114
- };
115
-
116
- return table;
117
- }
@@ -1,70 +0,0 @@
1
- import * as React from 'react';
2
- import { TableSchema, collectTableSchema } from './table_schema';
3
- import { useTableSchemaEpoch } from './epoch_contexts';
4
- import { useDuckDBConnection } from './connection_provider';
5
-
6
- interface Props {
7
- /// The children
8
- children: React.ReactElement | React.ReactElement[];
9
- /// The schema
10
- schema?: string;
11
- /// The name
12
- name: string;
13
- }
14
-
15
- interface State {
16
- /// The schema
17
- schema: string | null;
18
- /// The name
19
- name: string | null;
20
- /// The metadata
21
- metadata: TableSchema | null;
22
- /// The own epoch
23
- ownEpoch: number | null;
24
- }
25
-
26
- export const TABLE_METADATA = React.createContext<TableSchema | null>(null);
27
- export const useTableSchema = (): TableSchema | null => React.useContext(TABLE_METADATA);
28
-
29
- export const DuckDBTableSchemaProvider: React.FC<Props> = (props: Props) => {
30
- const conn = useDuckDBConnection();
31
- const epoch = useTableSchemaEpoch();
32
- const [state, setState] = React.useState<State>({
33
- schema: null,
34
- name: null,
35
- ownEpoch: epoch,
36
- metadata: null,
37
- });
38
- const inFlight = React.useRef<boolean>(false);
39
-
40
- // Detect unmount
41
- const isMounted = React.useRef(true);
42
- React.useEffect(() => {
43
- return () => void (isMounted.current = false);
44
- }, []);
45
-
46
- // Resolve the metadata
47
- React.useEffect(() => {
48
- if (!isMounted.current || !conn || inFlight.current) {
49
- return;
50
- }
51
- inFlight.current = true;
52
- const resolve = async (schema: string, name: string, epoch: number | null) => {
53
- const metadata = await collectTableSchema(conn!, {
54
- tableSchema: schema,
55
- tableName: name,
56
- });
57
- inFlight.current = false;
58
- if (!isMounted.current) return;
59
- setState({
60
- schema,
61
- name,
62
- ownEpoch: epoch,
63
- metadata,
64
- });
65
- };
66
- resolve(props.schema || 'main', props.name, epoch).catch(e => console.error(e));
67
- }, [conn, props.schema, props.name, epoch]);
68
-
69
- return <TABLE_METADATA.Provider value={state.metadata}>{props.children}</TABLE_METADATA.Provider>;
70
- };