Skip to content

improvement: rework Store.toSQL function to minimize UPDATE statements #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
43 changes: 13 additions & 30 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"devDependencies": {
"@snaplet/eslint-config": "workspace:*",
"@snaplet/tsconfig": "workspace:*",
"eslint": "8.56.0",
"knip": "5.0.1",
"skott": "0.32.1",
"turbo": "1.12.4",
"typescript": "5.3.3",
"vitest": "1.2.2"
"eslint": "8.57.0",
"knip": "5.0.3",
"skott": "0.33.0",
"turbo": "1.12.5",
"typescript": "5.4.2",
"vitest": "1.3.1"
},
"scripts": {
"build": "turbo run build",
Expand Down
10 changes: 5 additions & 5 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
}
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "7.0.1",
"@typescript-eslint/parser": "7.0.1",
"eslint": "8.56.0",
"@typescript-eslint/eslint-plugin": "7.1.1",
"@typescript-eslint/parser": "7.1.1",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-i": "2.29.1",
"eslint-plugin-node-import": "1.0.4",
"eslint-plugin-perfectionist": "2.5.0",
"eslint-plugin-perfectionist": "2.6.0",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-unused-imports": "3.1.0",
"eslint-plugin-vitest": "0.3.22",
"globals": "14.0.0",
"prettier": "3.2.5"
},
"devDependencies": {
"@types/eslint": "8.56.2"
"@types/eslint": "8.56.5"
}
}
18 changes: 9 additions & 9 deletions packages/seed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,39 @@
"@total-typescript/ts-reset": "0.5.1",
"@types/better-sqlite3": "7.6.9",
"@types/fs-extra": "11.0.4",
"@types/node": "20.11.18",
"@types/pg": "8.11.0",
"@types/node": "20.11.25",
"@types/pg": "8.11.2",
"@types/tmp": "0.2.6",
"@types/uuid": "9.0.8",
"@types/yargs": "17.0.32",
"better-sqlite3": "9.4.3",
"eslint": "8.56.0",
"eslint": "8.57.0",
"execa": "8.0.1",
"fs-extra": "11.2.0",
"postgres": "3.4.3",
"tmp-promise": "3.0.3",
"tsx": "4.7.1",
"typescript": "5.3.3",
"typescript": "5.4.2",
"uuid": "9.0.1",
"vitest": "1.2.2"
"vitest": "1.3.1"
},
"peerDependencies": {
"@snaplet/copycat": ">=2.0.0",
"drizzle-orm": "^0.29.3"
},
"dependencies": {
"@babel/types": "7.23.9",
"@babel/types": "7.24.0",
"@scaleleap/pg-format": "^1.0.0",
"@trpc/client": "10.45.1",
"@trpc/server": "10.45.1",
"c12": "1.8.0",
"c12": "1.10.0",
"find-up": "7.0.0",
"inflection": "^3.0.0",
"javascript-stringify": "2.1.0",
"json-schema-library": "9.1.3",
"ora": "8.0.1",
"quicktype-core": "^23.0.104",
"remeda": "^1.41.0",
"quicktype-core": "^23.0.105",
"remeda": "^1.47.0",
"yargs": "^17.7.2",
"zod": "3.22.4"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/seed/src/core/codegen/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { findUp } from "find-up";
import { mkdirp } from "fs-extra/esm";
import { writeFile } from "node:fs/promises";
import path from "node:path";
import { type DataModel } from "#core/dataModel/types.js";
import { type Dialect } from "#core/dialect/types.js";
import { type Fingerprint } from "#core/fingerprint/types.js";
import { type TableShapePredictions } from "#trpc/shapes.js";
import { type DataModel } from "../dataModel/types.js";
import { type Dialect } from "../dialect/types.js";
import { type Fingerprint } from "../fingerprint/types.js";
import { generateUserModels } from "./userModels/generateUserModels.js";

export interface CodegenContext {
Expand Down
18 changes: 9 additions & 9 deletions packages/seed/src/core/codegen/userModels/generateUserModels.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { stringify } from "javascript-stringify";
import { type CodegenContext } from "#core/codegen/codegen.js";
import { type Shape, type TableShapePredictions } from "#trpc/shapes.js";
import { type CodegenContext } from "../../codegen/codegen.js";
import { shouldGenerateFieldValue } from "../../dataModel/shouldGenerateFieldValue.js";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgoux bikeshed, but just checking if these .. paths are intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, they live in the same "module" which is #core.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so convention-wise, we should use ../../ if its in the same "module" (e.g. code in core/ importing other code in core/, and # if its in a different module (e.g. code in dialect/ importing code in core/)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it's very informal, so I wouldn't obsess on it. It's just a way for me to keep layers of responsibility separated. If I see a "#" I know it's from another layer of responsibility.

import {
type DataModel,
type DataModelField,
type DataModelModel,
type DataModelScalarField,
} from "#core/dataModel/types.js";
import { type Dialect } from "#core/dialect/types.js";
import { isJsonField } from "#core/fingerprint/fingerprint.js";
import { type Fingerprint } from "#core/fingerprint/types.js";
import { generateCodeFromTemplate } from "#core/userModels/templates/codegen.js";
import { type UserModels } from "#core/userModels/types.js";
import { type Shape, type TableShapePredictions } from "#trpc/shapes.js";
import { shouldGenerateFieldValue } from "../../dataModel/shouldGenerateFieldValue.js";
} from "../../dataModel/types.js";
import { type Dialect } from "../../dialect/types.js";
import { isJsonField } from "../../fingerprint/fingerprint.js";
import { type Fingerprint } from "../../fingerprint/types.js";
import { generateCodeFromTemplate } from "../../userModels/templates/codegen.js";
import { type UserModels } from "../../userModels/types.js";
import { generateJsonField } from "./generateJsonField.js";

export const SHAPE_PREDICTION_CONFIDENCE_THRESHOLD = 0.65;
Expand Down
2 changes: 1 addition & 1 deletion packages/seed/src/core/dialect/getDialect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type DataModel } from "#core/dataModel/types.js";
import { type DataModel } from "../dataModel/types.js";
import { type Dialect } from "./types.js";

export const getDialect = async (
Expand Down
6 changes: 3 additions & 3 deletions packages/seed/src/core/dialect/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type DataModel } from "#core/dataModel/types.js";
import { type Fingerprint } from "#core/fingerprint/types.js";
import { type Templates } from "#core/userModels/templates/types.js";
import { type Shape } from "#trpc/shapes.js";
import { type DataModel } from "../dataModel/types.js";
import { type Fingerprint } from "../fingerprint/types.js";
import { type Templates } from "../userModels/templates/types.js";

export type NestedType = string;

Expand Down
2 changes: 1 addition & 1 deletion packages/seed/src/core/plan/plan.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { copycat } from "@snaplet/copycat";
import { shouldGenerateFieldValue } from "#core/dataModel/shouldGenerateFieldValue.js";
import { type ClientState } from "../client/types.js";
import { serializeModelValues, serializeValue } from "../data/data.js";
import { type Json } from "../data/types.js";
import { shouldGenerateFieldValue } from "../dataModel/shouldGenerateFieldValue.js";
import {
type DataModel,
type DataModelObjectField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type DataModelField,
type DataModelModel,
type DataModelScalarField,
} from "#core/dataModel/types.js";
} from "../dataModel/types.js";

export function updateDataModelSequences(
currentDataModel: DataModel,
Expand Down
Loading
Loading