Skip to content

Commit 50695f6

Browse files
committed
update test
1 parent 0f03d7c commit 50695f6

3 files changed

Lines changed: 50 additions & 24 deletions

File tree

testing/doltgres-orm-tests/doltgres-orm-tests.bats

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,13 @@ teardown() {
2424
npx drizzle-kit push
2525

2626
# we can check if 'components table was created'
27-
query_server -c "SELECT * FROM components" -t
27+
query_server -c "SELECT * FROM users" -t
28+
run query_server -c "SELECT * FROM users" -t
29+
[ "$status" -eq 0 ]
30+
31+
npx tsx src/index.ts
32+
query_server -c "SELECT * FROM users" -t
33+
run query_server -c "SELECT age FROM users" -t
34+
[ "$status" -eq 0 ]
35+
[[ "$output" =~ "31" ]] || false
2836
}
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import { jsonb, pgTable, text } from 'drizzle-orm/pg-core';
1+
import { jsonb, integer, pgTable, varchar } from 'drizzle-orm/pg-core';
22

3-
export const components = pgTable(
4-
'components',
5-
{
6-
id: text('id').notNull(),
7-
name: text('name'),
8-
description: text('description'),
9-
render: jsonb('render'),
10-
}
11-
);
3+
export const usersTable = pgTable("users", {
4+
id: integer().primaryKey(),
5+
name: varchar({ length: 255 }).notNull(),
6+
age: integer().notNull(),
7+
email: varchar({ length: 255 }).notNull().unique(),
8+
render: jsonb('render'),
9+
});
Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
11
import 'dotenv/config';
22
import { Pool } from 'pg';
33
import { drizzle } from 'drizzle-orm/node-postgres';
4-
import { components } from "./db/schema";
5-
6-
const params = {
7-
id: 'test',
8-
render: null,
9-
name: 'Test',
10-
description: null,
11-
};
4+
import { usersTable } from "./db/schema";
5+
import { eq } from 'drizzle-orm';
126

137
const connectionString = 'postgres://postgres:password@localhost:5432/postgres';
14-
158
const pool = new Pool({ connectionString });
16-
179
const db = drizzle(pool);
1810

19-
await db
20-
.insert(components)
21-
.values(params)
11+
async function main() {
12+
const user: typeof usersTable.$inferInsert = {
13+
id: 1,
14+
name: 'John',
15+
age: 30,
16+
render: null,
17+
email: 'john@example.com',
18+
};
19+
await db.insert(usersTable).values(user);
20+
console.log('New user created!')
21+
const users = await db.select().from(usersTable);
22+
console.log('Getting all users from the database: ', users)
23+
/*
24+
const users: {
25+
id: number;
26+
name: string;
27+
age: number;
28+
email: string;
29+
render: jsonb;
30+
}[]
31+
*/
32+
await db
33+
.update(usersTable)
34+
.set({
35+
age: 31,
36+
})
37+
.where(eq(usersTable.email, user.email));
38+
console.log('User info updated!')
39+
}
40+
41+
main();

0 commit comments

Comments
 (0)