Skip to content

Commit

Permalink
Merge branch 'feature/singlestore-integration-tests' of https://githu…
Browse files Browse the repository at this point in the history
…b.com/singlestore-labs/summer-hackathon-s2-drizzle-orm into feature/singlestore-integration-tests
  • Loading branch information
apeng-singlestore committed Aug 30, 2024
2 parents c1ac319 + 3ca0df4 commit 5a8ad0e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
20 changes: 11 additions & 9 deletions integration-tests/tests/singlestore/singlestore-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const usersTable = singlestoreTable('userstest', {
name: text('name').notNull(),
verified: boolean('verified').notNull().default(false),
jsonb: json('jsonb').$type<string[]>(),
createdAt: timestamp('created_at', { fsp: 2 }).notNull().defaultNow(),
createdAt: timestamp('created_at', { fsp: 6 }).notNull().defaultNow(),
});

const users2Table = singlestoreTable('users2', {
Expand All @@ -121,10 +121,10 @@ const datesTable = singlestoreTable('datestable', {
date: date('date'),
dateAsString: date('date_as_string', { mode: 'string' }),
time: time('time', { fsp: 1 }),
datetime: datetime('datetime', { fsp: 2 }),
datetimeAsString: datetime('datetime_as_string', { fsp: 2, mode: 'string' }),
timestamp: timestamp('timestamp', { fsp: 3 }),
timestampAsString: timestamp('timestamp_as_string', { fsp: 3, mode: 'string' }),
datetime: datetime('datetime', { fsp: 6 }),
datetimeAsString: datetime('datetime_as_string', { fsp: 6, mode: 'string' }),
timestamp: timestamp('timestamp', { fsp: 6 }),
timestampAsString: timestamp('timestamp_as_string', { fsp: 6, mode: 'string' }),
year: year('year'),
});

Expand Down Expand Up @@ -175,7 +175,7 @@ const usersMySchemaTable = mySchema.table('userstest', {
name: text('name').notNull(),
verified: boolean('verified').notNull().default(false),
jsonb: json('jsonb').$type<string[]>(),
createdAt: timestamp('created_at', { fsp: 2 }).notNull().defaultNow(),
createdAt: timestamp('created_at', { fsp: 6 }).notNull().defaultNow(),
});

const users2MySchemaTable = mySchema.table('users2', {
Expand Down Expand Up @@ -985,7 +985,7 @@ export function tests(driver?: string) {

expect(query).toEqual({
sql:
'insert into `userstest` (`id`, `name`, `verified`, `jsonb`, `created_at`) values (?, ?, default, ?, default) on duplicate key update `name` = ?',
'insert into `userstest` (`id`, `name`, `verified`, `jsonb`, `created_at`) values (?, ?, default, ?, default) on duplicate key update `id` = ?, `name` = ?',
params: ['John', '["foo","bar"]', 'John1'],
});
});
Expand Down Expand Up @@ -1764,9 +1764,10 @@ export function tests(driver?: string) {
const sq = db
.select({ name: sql<string>`concat(${users2Table.name}, " modified")`.as('name') })
.from(users2Table)
.orderBy(asc(users2Table.id))
.as('sq');

const res = await db.select({ name: sq.name }).from(sq).orderBy(asc(users2Table.id));
const res = await db.select({ name: sq.name }).from(sq);

expect(res).toEqual([{ name: 'John modified' }, { name: 'Jane modified' }]);
});
Expand Down Expand Up @@ -1821,6 +1822,7 @@ export function tests(driver?: string) {
}]);

await db.insert(users2Table).values([{ id: 1, name: 'John', cityId: 1 }, { id: 2, name: 'Jane', cityId: 1 }, {
id: 3,
name: 'Jack',
cityId: 2,
}]);
Expand Down Expand Up @@ -2485,7 +2487,7 @@ export function tests(driver?: string) {
create table \`datestable\` (
\`datetime_utc\` datetime(6),
\`datetime\` datetime(6),
\`datetime_as_string\` datetime
\`datetime_as_string\` datetime(6)
)
`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ const usersTable = singlestoreTable('userstest', {
name: customText('name').notNull(),
verified: customBoolean('verified').notNull().default(false),
jsonb: customJson<string[]>('jsonb'),
createdAt: customTimestamp('created_at', { fsp: 2 }).notNull().default(sql`now()`),
createdAt: customTimestamp('created_at', { fsp: 6 }).notNull().default(sql`now()`),
});

const datesTable = singlestoreTable('datestable', {
date: date('date'),
dateAsString: date('date_as_string', { mode: 'string' }),
time: time('time', { fsp: 1 }),
datetime: datetime('datetime', { fsp: 2 }),
datetimeAsString: datetime('datetime_as_string', { fsp: 2, mode: 'string' }),
datetime: datetime('datetime', { fsp: 6 }),
datetimeAsString: datetime('datetime_as_string', { fsp: 6, mode: 'string' }),
year: year('year'),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const usersTable = singlestoreTable('userstest', {
name: text('name').notNull(),
verified: boolean('verified').notNull().default(false),
jsonb: json('jsonb').$type<string[]>(),
createdAt: timestamp('created_at', { fsp: 2 }).notNull().defaultNow(),
createdAt: timestamp('created_at', { fsp: 6 }).notNull().defaultNow(),
});

const users2Table = singlestoreTable('users2', {
Expand Down Expand Up @@ -639,8 +639,8 @@ test('insert + select all possible dates', async () => {
date: date('date'),
dateAsString: date('date_as_string', { mode: 'string' }),
time: time('time', { fsp: 1 }),
datetime: datetime('datetime', { fsp: 2 }),
datetimeAsString: datetime('datetime_as_string', { fsp: 2, mode: 'string' }),
datetime: datetime('datetime', { fsp: 6 }),
datetimeAsString: datetime('datetime_as_string', { fsp: 6, mode: 'string' }),
year: year('year'),
});

Expand Down Expand Up @@ -1272,6 +1272,9 @@ test('timestamp timezone', async () => {
});
const users = await db.select().from(usersTable);

console.log(users[0]!.createdAt, users[1]!.createdAt);
console.log(Date.now());

// check that the timestamps are set correctly for default times
expect(Math.abs(users[0]!.createdAt.getTime() - Date.now())).toBeLessThan(2000);

Expand Down

0 comments on commit 5a8ad0e

Please sign in to comment.