-
Notifications
You must be signed in to change notification settings - Fork 58
Added executeRaw() #482
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
Merged
Merged
Added executeRaw() #482
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6877d2c
Introduced executeRaw to DBAdapter and WASQLiteConnection.
Chriztiaan 87ab847
Cleanup.
Chriztiaan 20a758e
Added executeRaw to RNQS db adapter, using .execute as fallback inste…
Chriztiaan 7701fe2
Merge branch 'main' into feat/execute-raw
Chriztiaan cb3afd3
Added executeRaw to `@powersync/node`.
Chriztiaan a3beb5b
Changeset entries.
Chriztiaan 6e49cf9
Merge branch 'main' into feat/execute-raw
Chriztiaan 3ab99a0
Added jsdoc result example to executeRaw. Simplified RNQS adapter cha…
Chriztiaan 738a65e
Stripping column information from RNQS raw result.
Chriztiaan dbe68fe
Removed redundant Object.values() calls, because executeRaw doesn't c…
Chriztiaan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@powersync/react-native': minor | ||
--- | ||
|
||
Introduced `executeRaw` member to `RNQSDBAdapter` to match `DBAdapter` interface. | ||
It handles SQLite query results differently to `execute` - to preserve all columns, preventing duplicate column names from being overwritten. | ||
|
||
The implementation for RNQS will currently fall back to `execute`, preserving current behavior. Users requiring this functionality should migrate to `@powersync/op-sqlite`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@powersync/drizzle-driver': minor | ||
--- | ||
|
||
Using `executeRaw` internally for queries instead of `execute`. This function processes SQLite query results differently to preserve all columns, preventing duplicate column names from being overwritten. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@powersync/op-sqlite': minor | ||
'@powersync/common': minor | ||
'@powersync/node': minor | ||
'@powersync/web': minor | ||
--- | ||
|
||
Introduced `executeRaw`, which processes SQLite query results differently to preserve all columns, preventing duplicate column names from being overwritten. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
packages/drizzle-driver/tests/sqlite/relationship.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { AbstractPowerSyncDatabase, column, Schema, Table } from '@powersync/common'; | ||
import { PowerSyncDatabase } from '@powersync/web'; | ||
import { eq, relations } from 'drizzle-orm'; | ||
import { sqliteTable, text } from 'drizzle-orm/sqlite-core'; | ||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'; | ||
import * as SUT from '../../src/sqlite/PowerSyncSQLiteDatabase'; | ||
|
||
const users = new Table({ | ||
name: column.text | ||
}); | ||
|
||
const posts = new Table({ | ||
content: column.text, | ||
title: column.text, | ||
user_id: column.text | ||
}); | ||
|
||
const drizzleUsers = sqliteTable('users', { | ||
id: text('id').primaryKey().notNull(), | ||
name: text('name').notNull() | ||
}); | ||
|
||
const drizzlePosts = sqliteTable('posts', { | ||
id: text('id').primaryKey().notNull(), | ||
content: text('content').notNull(), | ||
title: text('title').notNull(), | ||
user_id: text('user_id') | ||
.notNull() | ||
.references(() => drizzleUsers.id) | ||
}); | ||
|
||
const usersRelations = relations(drizzleUsers, ({ one, many }) => ({ | ||
posts: many(drizzlePosts) | ||
})); | ||
|
||
const postsRelations = relations(drizzlePosts, ({ one }) => ({ | ||
user: one(drizzleUsers, { | ||
fields: [drizzlePosts.user_id], | ||
references: [drizzleUsers.id] | ||
}) | ||
})); | ||
|
||
const PsSchema = new Schema({ users, posts }); | ||
const DrizzleSchema = { users: drizzleUsers, posts: drizzlePosts, usersRelations, postsRelations }; | ||
|
||
describe('Relationship tests', () => { | ||
let powerSyncDb: AbstractPowerSyncDatabase; | ||
let db: SUT.PowerSyncSQLiteDatabase<typeof DrizzleSchema>; | ||
|
||
beforeEach(async () => { | ||
powerSyncDb = new PowerSyncDatabase({ | ||
database: { | ||
dbFilename: 'test.db' | ||
}, | ||
schema: PsSchema | ||
}); | ||
db = SUT.wrapPowerSyncWithDrizzle(powerSyncDb, { schema: DrizzleSchema, logger: { logQuery: () => {} } }); | ||
|
||
await powerSyncDb.init(); | ||
|
||
await db.insert(drizzleUsers).values({ id: '1', name: 'Alice' }); | ||
await db.insert(drizzlePosts).values({ id: '33', content: 'Post content', title: 'Post title', user_id: '1' }); | ||
}); | ||
|
||
afterEach(async () => { | ||
await powerSyncDb?.disconnectAndClear(); | ||
}); | ||
|
||
it('should retrieve a user with posts', async () => { | ||
const result = await db.query.users.findMany({ with: { posts: true } }); | ||
|
||
expect(result).toEqual([ | ||
{ id: '1', name: 'Alice', posts: [{ id: '33', content: 'Post content', title: 'Post title', user_id: '1' }] } | ||
]); | ||
}); | ||
|
||
it('should retrieve a post with its user', async () => { | ||
const result = await db.query.posts.findMany({ with: { user: true } }); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
id: '33', | ||
content: 'Post content', | ||
title: 'Post title', | ||
user_id: '1', | ||
user: { id: '1', name: 'Alice' } | ||
} | ||
]); | ||
}); | ||
|
||
it('should return a user and posts using leftJoin', async () => { | ||
const result = await db | ||
.select() | ||
.from(drizzleUsers) | ||
.leftJoin(drizzlePosts, eq(drizzleUsers.id, drizzlePosts.user_id)); | ||
|
||
expect(result[0].users).toEqual({ id: '1', name: 'Alice' }); | ||
expect(result[0].posts).toEqual({ id: '33', content: 'Post content', title: 'Post title', user_id: '1' }); | ||
}); | ||
|
||
it('should return a user and posts using rightJoin', async () => { | ||
const result = await db | ||
.select() | ||
.from(drizzleUsers) | ||
.rightJoin(drizzlePosts, eq(drizzleUsers.id, drizzlePosts.user_id)); | ||
|
||
expect(result[0].users).toEqual({ id: '1', name: 'Alice' }); | ||
expect(result[0].posts).toEqual({ id: '33', content: 'Post content', title: 'Post title', user_id: '1' }); | ||
}); | ||
|
||
it('should return a user and posts using fullJoin', async () => { | ||
const result = await db | ||
.select() | ||
.from(drizzleUsers) | ||
.fullJoin(drizzlePosts, eq(drizzleUsers.id, drizzlePosts.user_id)); | ||
|
||
expect(result[0].users).toEqual({ id: '1', name: 'Alice' }); | ||
expect(result[0].posts).toEqual({ id: '33', content: 'Post content', title: 'Post title', user_id: '1' }); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.