-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If we're passed sql in update/insert don't run it through mapToDriver…
…Value
- Loading branch information
Showing
7 changed files
with
64 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import {getSql, getTable, hasSql, hasTable, type HasSql} from '../Internal.ts' | ||
import {sql, type Sql} from '../Sql.ts' | ||
import {type HasSql, getSql, getTable, hasSql, hasTable} from '../Internal.ts' | ||
import {type Sql, sql} from '../Sql.ts' | ||
|
||
export type Input<T = unknown> = HasSql<T> | T | ||
|
||
export function input<T>(value: Input<T>): Sql<T> { | ||
if (typeof value !== 'object' || value === null) return sql.value(value) | ||
if (hasTable(value)) return sql.identifier(getTable(value).name) | ||
if (hasSql(value)) return getSql(value) as Sql<T> | ||
if (hasSql(value)) return getSql(value) | ||
return sql.value(value) | ||
} |
This file contains 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 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 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 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,30 @@ | ||
import {type Database, eq} from '@/index.ts' | ||
import type {DefineTest} from '@alinea/suite' | ||
import {concat} from '../../src/universal.ts' | ||
import {Node} from './schema.ts' | ||
|
||
export function testUpdate(db: Database, test: DefineTest) { | ||
test('update', async () => { | ||
await db.create(Node) | ||
try { | ||
await db.insert(Node).values({ | ||
textField: 'hello', | ||
bool: true | ||
}) | ||
|
||
await db | ||
.update(Node) | ||
.set({textField: concat(Node.textField, ' world')}) | ||
.where(eq(Node.textField, 'hello')) | ||
|
||
const node = await db.select().from(Node).get() | ||
test.equal(node, { | ||
id: 1, | ||
textField: 'hello world', | ||
bool: true | ||
}) | ||
} finally { | ||
await db.drop(Node) | ||
} | ||
}) | ||
} |
This file contains 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