Skip to content

Commit

Permalink
Interim
Browse files Browse the repository at this point in the history
  • Loading branch information
benmerckx committed May 6, 2024
1 parent 9716f3d commit c203cc3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export * from './core/Column.ts'
export * from './core/Constraint.ts'
export * from './core/Database.ts'
export * from './core/Driver.ts'
export * from './core/Expr.ts'
export * from './core/Index.ts'
export * from './core/Query.ts'
export * from './core/Selection.ts'
export * from './core/Sql.ts'
Expand Down
2 changes: 1 addition & 1 deletion src/sqlite/SqliteDialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SqliteEmitter extends Emitter {
)
}
emitIdColumn() {
this.sql += 'integer primary key autoincrement'
this.sql += 'integer'
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/universal/UniversalColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {sql} from '../core/Sql.ts'
export function id(name?: string): Column<number> {
return new Column({
name,
type: sql.chunk('emitIdColumn', undefined)
type: sql.chunk('emitIdColumn', undefined),
primary: true
})
}

Expand Down
47 changes: 46 additions & 1 deletion test/TestDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type SyncDatabase
} from '../src/core/Database.ts'
import {table} from '../src/core/Table.ts'
import {eq, sql} from '../src/index.ts'
import {eq, foreignKey, primaryKey, sql, unique} from '../src/index.ts'
import {boolean, id, int, json, text} from '../src/universal.ts'

const Node = table('Node', {
Expand All @@ -25,6 +25,27 @@ const Post = table('Post', {
title: text().notNull()
})

const TableA = table('TableA', {
id: id()
})

const TableB = table(
'TableB',
{
isUnique: int().unique(),
hasRef: int().references(TableA.id),
colA: int(),
colB: int().unique()
},
TableB => {
return {
uniqueA: unique().on(TableB.colA),
multiPk: primaryKey(TableB.colA, TableB.colB),
multiRef: foreignKey(TableB.colA).references(TableA.id)
}
}
)

export async function testDriver(
name: string,
createDb: () => Promise<Database>
Expand Down Expand Up @@ -198,5 +219,29 @@ export async function testDriver(
}
}
})

Test.it('constraints and indexes', async () => {
//try {
await db.createTable(TableA)
await db.createTable(TableB)
await db.insert(TableA).values({})
await db.insert(TableB).values({
isUnique: 1,
hasRef: 1,
colA: 1,
colB: 1
})
const [row] = await db.select().from(TableB)
Assert.isEqual(row, {
isUnique: 1,
hasRef: 1,
colA: 1,
colB: 1
})
/*} finally {
await db.dropTable(TableB)
await db.dropTable(TableA)
}*/
})
})
}

0 comments on commit c203cc3

Please sign in to comment.