Skip to content

Commit 7ba4d11

Browse files
authored
Parse returned mysql schema result (#122)
* Bugfix:Parse returned schema info as an object. Previously this was the default, but since a recent change to the mysql connection options, all JSON fields are now returned as strings.
1 parent 5a58f45 commit 7ba4d11

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

.changeset/healthy-rules-arrive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/service-module-mysql': patch
3+
---
4+
5+
Fixed mysql schema json parsing

modules/module-mysql/src/api/MySQLRouteAPIAdapter.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { toExpressionTypeFromMySQLType } from '../common/common-index.js';
1111
type SchemaResult = {
1212
schema_name: string;
1313
table_name: string;
14-
columns: Array<{ data_type: string; column_name: string }>;
14+
columns: string;
1515
};
1616

1717
export class MySQLRouteAPIAdapter implements api.RouteAPI {
@@ -326,16 +326,18 @@ export class MySQLRouteAPIAdapter implements api.RouteAPI {
326326
name: result.schema_name,
327327
tables: []
328328
});
329+
330+
const columns = JSON.parse(result.columns).map((column: { data_type: string; column_name: string }) => ({
331+
name: column.column_name,
332+
type: column.data_type,
333+
sqlite_type: toExpressionTypeFromMySQLType(column.data_type).typeFlags,
334+
internal_type: column.data_type,
335+
pg_type: column.data_type
336+
}));
329337

330338
schema.tables.push({
331339
name: result.table_name,
332-
columns: result.columns.map((column) => ({
333-
name: column.column_name,
334-
type: column.data_type,
335-
sqlite_type: toExpressionTypeFromMySQLType(column.data_type).typeFlags,
336-
internal_type: column.data_type,
337-
pg_type: column.data_type
338-
}))
340+
columns: columns
339341
});
340342

341343
return hash;

0 commit comments

Comments
 (0)