Skip to content

Commit

Permalink
Use correct query syntax for creating records (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
leo authored Jan 28, 2025
1 parent 4b09fbb commit 7b5575f
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 17 deletions.
Binary file modified bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
"resolve-from": "5.0.0"
},
"devDependencies": {
"ronin": "6.0.22",
"ronin": "6.0.25",
"@biomejs/biome": "1.9.4",
"@types/bun": "1.2.0",
"@types/bun": "1.2.1",
"@types/ini": "4.1.1",
"bun-bagel": "1.1.0",
"tsup": "8.3.5",
"tsup": "8.3.6",
"typescript": "5.7.3"
}
}
2 changes: 1 addition & 1 deletion src/utils/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const createTempModelQuery = (
queries.push(createModelQuery(tempModelSlug, { fields }));

// Move all the data to the copied model
queries.push(`add.${tempModelSlug}.to(() => get.${modelSlug}())`);
queries.push(`add.${tempModelSlug}.with(() => get.${modelSlug}())`);

if (customQueries) {
queries.push(...customQueries);
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export const TestD = model({
action: 'INSERT',
when: 'BEFORE',
// @ts-expect-error Fix in models
effects: (): Array<Effect> => [add.comment.to({ name: 'Test' })],
effects: (): Array<Effect> => [add.comment.with({ name: 'Test' })],
},
],
}) as unknown as Model;
Expand All @@ -212,7 +212,7 @@ export const TestE = model({
action: 'DELETE',
when: 'AFTER',
// @ts-expect-error Fix in models
effects: (): Array<Effect> => [add.comment.to({ name: 'Test' })],
effects: (): Array<Effect> => [add.comment.with({ name: 'Test' })],
},
],
}) as unknown as Model;
Expand Down
4 changes: 2 additions & 2 deletions tests/utils/field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe('fields', () => {
expect(diff).toHaveLength(4);
expect(diff).toStrictEqual([
"create.model({slug:'RONIN_TEMP_account',fields:[{type:'number', slug:'id', unique:true}]})",
'add.RONIN_TEMP_account.to(() => get.account())',
'add.RONIN_TEMP_account.with(() => get.account())',
'drop.model("account")',
'alter.model("RONIN_TEMP_account").to({slug: "account"})',
]);
Expand All @@ -197,7 +197,7 @@ describe('fields', () => {
expect(diff).toHaveLength(5);
expect(diff).toStrictEqual([
"create.model({slug:'RONIN_TEMP_account',fields:[{type:'link', slug:'profile', target:'profile'}]})",
'add.RONIN_TEMP_account.to(() => get.account())',
'add.RONIN_TEMP_account.with(() => get.account())',
'alter.model("RONIN_TEMP_account").alter.field("profile").to({slug: "newProfile"})',
'drop.model("account")',
'alter.model("RONIN_TEMP_account").to({slug: "account"})',
Expand Down
10 changes: 5 additions & 5 deletions tests/utils/migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('migration', () => {
expect(modelDiff).toHaveLength(4);
expect(modelDiff).toStrictEqual([
"create.model({slug:'RONIN_TEMP_account',fields:[{slug:'name', type:'string'}]})",
'add.RONIN_TEMP_account.to(() => get.account())',
'add.RONIN_TEMP_account.with(() => get.account())',
'drop.model("account")',
'alter.model("RONIN_TEMP_account").to({slug: "account"})',
]);
Expand Down Expand Up @@ -76,7 +76,7 @@ describe('migration', () => {
expect(modelDiff).toHaveLength(4);
expect(modelDiff).toStrictEqual([
"create.model({slug:'RONIN_TEMP_account',fields:[{slug:'name', required:true, unique:true, type:'string'}]})",
'add.RONIN_TEMP_account.to(() => get.account())',
'add.RONIN_TEMP_account.with(() => get.account())',
'drop.model("account")',
'alter.model("RONIN_TEMP_account").to({slug: "account"})',
]);
Expand All @@ -99,7 +99,7 @@ describe('migration', () => {
expect(modelDiff).toHaveLength(4);
expect(modelDiff).toStrictEqual([
"create.model({slug:'RONIN_TEMP_account',fields:[{slug:'name', type:'string'}]})",
'add.RONIN_TEMP_account.to(() => get.account())',
'add.RONIN_TEMP_account.with(() => get.account())',
'drop.model("account")',
'alter.model("RONIN_TEMP_account").to({slug: "account"})',
]);
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('migration', () => {

expect(modelDiff).toStrictEqual([
"create.model({slug:'comment',fields:[{slug:'name', type:'string'}]})",
'alter.model("comment").create.trigger({"action":"INSERT","when":"BEFORE","effects":[{"add":{"comment":{"to":{"name":"Test"}}}}]})',
'alter.model("comment").create.trigger({"action":"INSERT","when":"BEFORE","effects":[{"add":{"comment":{"with":{"name":"Test"}}}}]})',
]);
});

Expand All @@ -150,7 +150,7 @@ describe('migration', () => {
expect(modelDiff).toHaveLength(2);
expect(modelDiff).toStrictEqual([
'alter.model("comment").drop.trigger("no slug")',
'alter.model("comment").create.trigger({"action":"DELETE","when":"AFTER","effects":[{"add":{"comment":{"to":{"name":"Test"}}}}]})',
'alter.model("comment").create.trigger({"action":"DELETE","when":"AFTER","effects":[{"add":{"comment":{"with":{"name":"Test"}}}}]})',
]);
});
});
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/protocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('protocol', () => {

expect(statements).toHaveLength(1);
expect(statements[0].statement).toStrictEqual(
`SELECT "id", "ronin.locked", "ronin.createdAt", "ronin.createdBy", "ronin.updatedAt", "ronin.updatedBy", "handle" FROM "accounts" WHERE ("handle" = 'elaine') LIMIT 1`,
`SELECT "id", "ronin.locked", "ronin.createdAt", "ronin.createdBy", "ronin.updatedAt", "ronin.updatedBy", "handle" FROM "accounts" WHERE "handle" = 'elaine' LIMIT 1`,
);
});

Expand Down
6 changes: 3 additions & 3 deletions tests/utils/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('queries', () => {
const result = createTempModelQuery('user', fields, [], []);
expect(result).toEqual([
"create.model({slug:'RONIN_TEMP_user',fields:[{slug:'username', type:'string', name:'Username', unique:true, required:true}]})",
'add.RONIN_TEMP_user.to(() => get.user())',
'add.RONIN_TEMP_user.with(() => get.user())',
'drop.model("user")',
'alter.model("RONIN_TEMP_user").to({slug: "user"})',
]);
Expand All @@ -126,7 +126,7 @@ describe('queries', () => {
const result = createTempModelQuery('user', fields, [], [], customQueries);
expect(result).toEqual([
"create.model({slug:'RONIN_TEMP_user',fields:[{slug:'username', type:'string', name:'Username', unique:true, required:true}]})",
'add.RONIN_TEMP_user.to(() => get.user())',
'add.RONIN_TEMP_user.with(() => get.user())',
...customQueries,
'drop.model("user")',
'alter.model("RONIN_TEMP_user").to({slug: "user"})',
Expand All @@ -153,7 +153,7 @@ describe('queries', () => {
const result = createTempModelQuery('user', fields, [], triggers);
expect(result).toEqual([
"create.model({slug:'RONIN_TEMP_user',fields:[{slug:'username', type:'string', name:'Username', unique:true, required:true}]})",
'add.RONIN_TEMP_user.to(() => get.user())',
'add.RONIN_TEMP_user.with(() => get.user())',
'drop.model("user")',
'alter.model("RONIN_TEMP_user").to({slug: "user"})',
'alter.model("user").create.trigger({"action":"INSERT","when":"BEFORE","effects":[]})',
Expand Down

0 comments on commit 7b5575f

Please sign in to comment.