diff --git a/cli/prisma2/__snapshots__/integrate.mysql.test.ts.js b/cli/prisma2/__snapshots__/integrate.mysql.test.ts.js index 43cd5060efb6..760e66aef2de 100644 --- a/cli/prisma2/__snapshots__/integrate.mysql.test.ts.js +++ b/cli/prisma2/__snapshots__/integrate.mysql.test.ts.js @@ -19,7 +19,7 @@ model a { model b { id Int @default(autoincrement()) @id - a a @map(["one", "two"]) + a a @map(["one", "two"]) @relation(references: [one, two]) @@index([a], name: "one") } @@ -74,7 +74,7 @@ datasource mysql { model posts { id Int @default(autoincrement()) @id title String - user_id users + user_id users @relation(references: [id]) @@index([user_id], name: "user_id") } @@ -366,7 +366,7 @@ datasource mysql { model posts { id Int @default(autoincrement()) @id title String - user_id users + user_id users @relation(references: [id]) @@index([user_id], name: "user_id") } @@ -925,7 +925,182 @@ model migrate { } ` -exports['variables.findOne({ where: { variables_name_key_key: { key: \'b\', name: \'a\' } } })2'] = ` +exports['variables.findOne({ where: { variables_value_email_key: { value: \'c\', email: \'d\' } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource mysql { + provider = "mysql" + url = "***" +} + +model variables { + email String + key String + name String + value String + + @@id([name, key]) + @@unique([value, email], name: "variables_value_email_key") +} +` + +exports['await teams.updateMany({ data: { name: \'b\' }, where: { name: null }, }) client.teams.findMany();'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource mysql { + provider = "mysql" + url = "***" +} + +model teams { + id Int @default(autoincrement()) @id + name String? +} +` + +exports['users.findMany({ where: { email: \'MAX@PRISMA.IO\' } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource mysql { + provider = "mysql" + url = "***" +} + +model users { + email String @unique + id Int @default(autoincrement()) @id +} +` + +exports['events.findMany({ where: { time: null } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource mysql { + provider = "mysql" + url = "***" +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` + +exports['events.findMany({ where: { time: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource mysql { + provider = "mysql" + url = "***" +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` + +exports['events.findMany({ where: { time: { gt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource mysql { + provider = "mysql" + url = "***" +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` + +exports['events.findMany({ where: { time: { gte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource mysql { + provider = "mysql" + url = "***" +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` + +exports['events.findMany({ where: { time: { lt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource mysql { + provider = "mysql" + url = "***" +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` + +exports['events.findMany({ where: { time: { lte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource mysql { + provider = "mysql" + url = "***" +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` + +exports['events.findMany({ where: { time: { not: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource mysql { + provider = "mysql" + url = "***" +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` + +exports['variables.findOne({ where: { variables_name_key_key: { key: \'b\', name: \'a\' } } })'] = ` generator client { provider = "prisma-client-js" output = "***" @@ -947,7 +1122,7 @@ model variables { } ` -exports['variables.findOne({ where: { variables_value_email_key: { value: \'c\', email: \'d\' } } })'] = ` +exports['variables.findOne({ where: { name_key: { key: \'b\', name: \'a\' } } })'] = ` generator client { provider = "prisma-client-js" output = "***" @@ -965,11 +1140,10 @@ model variables { value String @@id([name, key]) - @@unique([value, email], name: "variables_value_email_key") } ` -exports['await teams.updateMany({ data: { name: \'b\' }, where: { name: null }, }) client.teams.findMany();'] = ` +exports['variables.update({ where: { name_key: { key: \'b\', name: \'a\' } }, data: { email: \'e\' }, })'] = ` generator client { provider = "prisma-client-js" output = "***" @@ -980,13 +1154,17 @@ datasource mysql { url = "***" } -model teams { - id Int @default(autoincrement()) @id - name String? +model variables { + email String + key String + name String + value String + + @@id([name, key]) } ` -exports['users.findMany({ where: { email: \'MAX@PRISMA.IO\' } })'] = ` +exports['variables.upsert({ where: { name_key: { key: \'b\', name: \'a\' } }, create: { name: \'1\', key: \'2\', value: \'3\', email: \'4\' }, update: { email: \'e\' }, })'] = ` generator client { provider = "prisma-client-js" output = "***" @@ -997,8 +1175,54 @@ datasource mysql { url = "***" } -model users { - email String @unique - id Int @default(autoincrement()) @id +model variables { + email String + key String + name String + value String + + @@id([name, key]) +} +` + +exports['variables.upsert({ where: { name_key: { key: \'d\', name: \'a\' } }, create: { name: \'1\', key: \'2\', value: \'3\', email: \'4\' }, update: { email: \'e\' }, })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource mysql { + provider = "mysql" + url = "***" +} + +model variables { + email String + key String + name String + value String + + @@id([name, key]) +} +` + +exports['variables.delete({ where: { name_key: { key: \'b\', name: \'a\' } }, })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource mysql { + provider = "mysql" + url = "***" +} + +model variables { + email String + key String + name String + value String + + @@id([name, key]) } ` diff --git a/cli/prisma2/__snapshots__/integrate.postgresql.test.ts.js b/cli/prisma2/__snapshots__/integrate.postgresql.test.ts.js index c93b69a24007..e4debadb9e5c 100644 --- a/cli/prisma2/__snapshots__/integrate.postgresql.test.ts.js +++ b/cli/prisma2/__snapshots__/integrate.postgresql.test.ts.js @@ -1,4 +1,4 @@ -exports['a.findOne({ where: { one_two: { one: 1, two: 2 } } })'] = ` +exports['users.findMany()'] = ` generator client { provider = "prisma-client-js" output = "***" @@ -9,17 +9,60 @@ datasource pg { url = "***" } -model a { - one Int - two Int - b b[] +model users { + email String? + id Int @default(autoincrement()) @id +} +` - @@id([one, two]) +exports['users.findMany({ where: { email: \'ada@prisma.io\' } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" } -model b { - id Int @default(autoincrement()) @id - a a @map(["one", "two"]) +datasource pg { + provider = "postgresql" + url = "***" +} + +model users { + email String @unique + id Int @default(autoincrement()) @id +} +` + +exports['users.findMany()2'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource pg { + provider = "postgresql" + url = "***" +} + +model users { + email String @unique + id Int @default(autoincrement()) @id +} +` + +exports['users.findMany({ where: { email: \'MAX@PRISMA.IO\' } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource pg { + provider = "postgresql" + url = "***" +} + +model users { + email String @unique + id Int @default(autoincrement()) @id } ` @@ -72,7 +115,7 @@ datasource pg { model posts { id Int @default(autoincrement()) @id title String - user_id users + user_id users @relation(references: [id]) } model users { @@ -297,57 +340,6 @@ model users { } ` -exports['users.findMany()'] = ` -generator client { - provider = "prisma-client-js" - output = "***" -} - -datasource pg { - provider = "postgresql" - url = "***" -} - -model users { - email String? - id Int @default(autoincrement()) @id -} -` - -exports['users.findMany({ where: { email: \'ada@prisma.io\' } })'] = ` -generator client { - provider = "prisma-client-js" - output = "***" -} - -datasource pg { - provider = "postgresql" - url = "***" -} - -model users { - email String @unique - id Int @default(autoincrement()) @id -} -` - -exports['users.findMany()2'] = ` -generator client { - provider = "prisma-client-js" - output = "***" -} - -datasource pg { - provider = "postgresql" - url = "***" -} - -model users { - email String @unique - id Int @default(autoincrement()) @id -} -` - exports['users.findOne({ where: { email: \'ada@prisma.io\' } }).posts()'] = ` generator client { provider = "prisma-client-js" @@ -362,7 +354,7 @@ datasource pg { model posts { id Int @default(autoincrement()) @id title String - user_id users + user_id users @relation(references: [id]) } model users { @@ -762,7 +754,7 @@ model posts { } ` -exports['teams.findMany({ where: { id: { in: [] } } })'] = ` +exports['events.findMany({ where: { time: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } })'] = ` generator client { provider = "prisma-client-js" output = "***" @@ -773,14 +765,115 @@ datasource pg { url = "***" } -model teams { - id Int @default(autoincrement()) @id - name String - token Int @unique +model events { + id Int @default(autoincrement()) @id + time DateTime? } ` -exports['teams.findMany({ where: { id: { in: [] }, token: { in: [11, 22] } } })'] = ` +exports['events.findMany({ where: { time: { gt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource pg { + provider = "postgresql" + url = "***" +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` + +exports['events.findMany({ where: { time: { gte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource pg { + provider = "postgresql" + url = "***" +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` + +exports['events.findMany({ where: { time: { lt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource pg { + provider = "postgresql" + url = "***" +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` + +exports['events.findMany({ where: { time: { lte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource pg { + provider = "postgresql" + url = "***" +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` + +exports['events.findMany({ where: { time: { not: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource pg { + provider = "postgresql" + url = "***" +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` + +exports['events.findMany({ where: { time: null } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource pg { + provider = "postgresql" + url = "***" +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` + +exports['teams.findMany({ where: { id: { in: [] } } })'] = ` generator client { provider = "prisma-client-js" output = "***" @@ -798,7 +891,7 @@ model teams { } ` -exports['teams.findMany({ where: { token: { in: [11, 22] } } })'] = ` +exports['teams.findMany({ where: { id: { in: [] }, token: { in: [11, 22] } } })'] = ` generator client { provider = "prisma-client-js" output = "***" @@ -816,7 +909,7 @@ model teams { } ` -exports['teams.findMany({ where: { token: { notIn: [11, 22] } } })'] = ` +exports['teams.findMany({ where: { token: { in: [11, 22] } } })'] = ` generator client { provider = "prisma-client-js" output = "***" @@ -834,7 +927,7 @@ model teams { } ` -exports['teams.findMany({ where: { token: { notIn: [] } } })'] = ` +exports['teams.findMany({ where: { token: { notIn: [11, 22] } } })'] = ` generator client { provider = "prisma-client-js" output = "***" @@ -852,7 +945,7 @@ model teams { } ` -exports['users.findMany({ where: { email: \'MAX@PRISMA.IO\' } })'] = ` +exports['teams.findMany({ where: { token: { notIn: [] } } })'] = ` generator client { provider = "prisma-client-js" output = "***" @@ -863,9 +956,10 @@ datasource pg { url = "***" } -model users { - email String @unique +model teams { id Int @default(autoincrement()) @id + name String + token Int @unique } ` @@ -936,7 +1030,112 @@ model migrate { } ` -exports['variables.findOne({ where: { variables_name_key_key: { key: \'b\', name: \'a\' } } })2'] = ` +exports['variables.findOne({ where: { name_key: { key: \'b\', name: \'a\' } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource pg { + provider = "postgresql" + url = "***" +} + +model variables { + email String + key String + name String + value String + + @@id([name, key]) +} +` + +exports['variables.update({ where: { name_key: { key: \'b\', name: \'a\' } }, data: { email: \'e\' }, })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource pg { + provider = "postgresql" + url = "***" +} + +model variables { + email String + key String + name String + value String + + @@id([name, key]) +} +` + +exports['variables.upsert({ where: { name_key: { key: \'b\', name: \'a\' } }, create: { name: \'1\', key: \'2\', value: \'3\', email: \'4\' }, update: { email: \'e\' }, })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource pg { + provider = "postgresql" + url = "***" +} + +model variables { + email String + key String + name String + value String + + @@id([name, key]) +} +` + +exports['variables.upsert({ where: { name_key: { key: \'d\', name: \'a\' } }, create: { name: \'1\', key: \'2\', value: \'3\', email: \'4\' }, update: { email: \'e\' }, })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource pg { + provider = "postgresql" + url = "***" +} + +model variables { + email String + key String + name String + value String + + @@id([name, key]) +} +` + +exports['variables.delete({ where: { name_key: { key: \'b\', name: \'a\' } }, })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource pg { + provider = "postgresql" + url = "***" +} + +model variables { + email String + key String + name String + value String + + @@id([name, key]) +} +` + +exports['variables.findOne({ where: { variables_name_key_key: { key: \'b\', name: \'a\' } } })'] = ` generator client { provider = "prisma-client-js" output = "***" @@ -980,6 +1179,31 @@ model variables { } ` +exports['a.findOne({ where: { one_two: { one: 1, two: 2 } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource pg { + provider = "postgresql" + url = "***" +} + +model a { + one Int + two Int + b b[] + + @@id([one, two]) +} + +model b { + id Int @default(autoincrement()) @id + a a @map(["one", "two"]) @relation(references: [one, two]) +} +` + exports['await teams.updateMany({ data: { name: \'b\' }, where: { name: null }, }) client.teams.findMany();'] = ` generator client { provider = "prisma-client-js" @@ -996,3 +1220,20 @@ model teams { name String? } ` + +exports['teams.update({ where: { token: 11 }, data: { token: 10 } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource pg { + provider = "postgresql" + url = "***" +} + +model teams { + id Int @default(autoincrement()) @id + token Int @unique +} +` diff --git a/cli/prisma2/__snapshots__/integrate.sqlite.test.ts.js b/cli/prisma2/__snapshots__/integrate.sqlite.test.ts.js index e8c26ee4e3c6..9c8e6e61b3c1 100644 --- a/cli/prisma2/__snapshots__/integrate.sqlite.test.ts.js +++ b/cli/prisma2/__snapshots__/integrate.sqlite.test.ts.js @@ -1,4 +1,4 @@ -exports['exercises.findOne({ where: { distance: 12.3 } })'] = ` +exports['const posts = await posts.findMany({ where: { created_at: { lte: new Date() } } }) posts.forEach(post => { assert_1.default.ok(post.created_at instanceof Date); delete post.created_at; }); posts;'] = ` generator client { provider = "prisma-client-js" output = "***" @@ -15,9 +15,10 @@ model teams { name String @unique } -model exercises { - distance Float @default(12.3) @unique - id Int @default(autoincrement()) @id +model posts { + created_at DateTime @default(now()) + id Int @default(autoincrement()) @id + title String } ` @@ -82,7 +83,7 @@ model users { model posts { id Int @default(autoincrement()) @id title String - user_id users + user_id users @relation(references: [id]) } ` @@ -342,7 +343,7 @@ model users { model posts { id Int @default(autoincrement()) @id title String - user_id users + user_id users @relation(references: [id]) } ` @@ -586,6 +587,78 @@ model crons { } ` +exports['posts.findMany({ where: { created_at: { gte: new Date() } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource sqlite { + provider = "sqlite" + url = "***" +} + +model teams { + email String @unique + id Int @id + name String @unique +} + +model posts { + created_at DateTime @default(now()) + id Int @default(autoincrement()) @id + title String +} +` + +exports['posts.findMany({ where: { created_at: { gt: new Date() } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource sqlite { + provider = "sqlite" + url = "***" +} + +model teams { + email String @unique + id Int @id + name String @unique +} + +model posts { + created_at DateTime @default(now()) + id Int @default(autoincrement()) @id + title String +} +` + +exports['const posts = await posts.findMany({ where: { created_at: { lt: new Date() } } }) posts.forEach(post => { assert_1.default.ok(post.created_at instanceof Date); delete post.created_at; }); posts;'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource sqlite { + provider = "sqlite" + url = "***" +} + +model teams { + email String @unique + id Int @id + name String @unique +} + +model posts { + created_at DateTime @default(now()) + id Int @default(autoincrement()) @id + title String +} +` + exports['teams.update({ where: { token: 11 }, data: { token: 10 } })'] = ` generator client { provider = "prisma-client-js" @@ -603,6 +676,98 @@ model teams { } ` +exports['await events.findMany({ where: { time: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource sqlite { + provider = "sqlite" + url = "***" +} + +model teams { + email String @unique + id Int @id + name String @unique +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` + +exports['events.findMany({ where: { time: { gt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource sqlite { + provider = "sqlite" + url = "***" +} + +model teams { + email String @unique + id Int @id + name String @unique +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` + +exports['events.findMany({ where: { time: { gte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource sqlite { + provider = "sqlite" + url = "***" +} + +model teams { + email String @unique + id Int @id + name String @unique +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` + +exports['events.findMany({ where: { time: { lte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource sqlite { + provider = "sqlite" + url = "***" +} + +model teams { + email String @unique + id Int @id + name String @unique +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` + exports['events.findMany({ where: { time: { not: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } })'] = ` generator client { provider = "prisma-client-js" @@ -621,8 +786,8 @@ model teams { } model events { - id Int @default(autoincrement()) @id - time String? + id Int @default(autoincrement()) @id + time DateTime? } ` @@ -716,7 +881,7 @@ model teams { } ` -exports['users.findMany({ where: { team_id: null } })'] = ` +exports['users.findMany({ where: { email: \'MAX@PRISMA.IO\' } })'] = ` generator client { provider = "prisma-client-js" output = "***" @@ -728,20 +893,18 @@ datasource sqlite { } model teams { - id Int @default(autoincrement()) @id - name String - token Int @unique - users users[] + email String @unique + id Int @id + name String @unique } model users { - email String @unique - id Int @default(autoincrement()) @id - team_id teams? + email String @unique + id Int @default(autoincrement()) @id } ` -exports['users.findMany({ where: { email: \'MAX@PRISMA.IO\' } })'] = ` +exports['exercises.findMany({ where: { distance: 12.213 } })'] = ` generator client { provider = "prisma-client-js" output = "***" @@ -758,13 +921,13 @@ model teams { name String @unique } -model users { - email String @unique - id Int @default(autoincrement()) @id +model exercises { + distance Float + id Int @default(autoincrement()) @id } ` -exports['exercises.findMany({ where: { distance: 12.213 } })'] = ` +exports['exercises.findOne({ where: { distance: 12.213 } })'] = ` generator client { provider = "prisma-client-js" output = "***" @@ -782,12 +945,12 @@ model teams { } model exercises { - distance Float + distance Float @unique id Int @default(autoincrement()) @id } ` -exports['exercises.findOne({ where: { distance: 12.213 } })'] = ` +exports['exercises.findOne({ where: { distance: 12.3 } })'] = ` generator client { provider = "prisma-client-js" output = "***" @@ -805,7 +968,7 @@ model teams { } model exercises { - distance Float @unique + distance Float @default(12.3) @unique id Int @default(autoincrement()) @id } ` @@ -832,6 +995,228 @@ model migrate { } ` +exports['variables.findOne({ where: { name_key: { key: \'b\', name: \'a\' } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource sqlite { + provider = "sqlite" + url = "***" +} + +model teams { + email String @unique + id Int @id + name String @unique +} + +model variables { + email String + key String + name String + value String + + @@id([name, key]) +} +` + +exports['variables.update({ where: { name_key: { key: \'b\', name: \'a\' } }, data: { email: \'e\' }, })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource sqlite { + provider = "sqlite" + url = "***" +} + +model teams { + email String @unique + id Int @id + name String @unique +} + +model variables { + email String + key String + name String + value String + + @@id([name, key]) +} +` + +exports['variables.upsert({ where: { name_key: { key: \'b\', name: \'a\' } }, create: { name: \'1\', key: \'2\', value: \'3\', email: \'4\' }, update: { email: \'e\' }, })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource sqlite { + provider = "sqlite" + url = "***" +} + +model teams { + email String @unique + id Int @id + name String @unique +} + +model variables { + email String + key String + name String + value String + + @@id([name, key]) +} +` + +exports['variables.upsert({ where: { name_key: { key: \'d\', name: \'a\' } }, create: { name: \'1\', key: \'2\', value: \'3\', email: \'4\' }, update: { email: \'e\' }, })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource sqlite { + provider = "sqlite" + url = "***" +} + +model teams { + email String @unique + id Int @id + name String @unique +} + +model variables { + email String + key String + name String + value String + + @@id([name, key]) +} +` + +exports['variables.delete({ where: { name_key: { key: \'b\', name: \'a\' } }, })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource sqlite { + provider = "sqlite" + url = "***" +} + +model teams { + email String @unique + id Int @id + name String @unique +} + +model variables { + email String + key String + name String + value String + + @@id([name, key]) +} +` + +exports['variables.findOne({ where: { sqlite_autoindex_variables_1: { key: \'b\', name: \'a\' } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource sqlite { + provider = "sqlite" + url = "***" +} + +model teams { + email String @unique + id Int @id + name String @unique +} + +model variables { + email String + id Int @default(autoincrement()) @id + key String + name String + value String + + @@unique([name, key], name: "sqlite_autoindex_variables_1") +} +` + +exports['variables.findOne({ where: { sqlite_autoindex_variables_2: { value: \'c\', email: \'d\' } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource sqlite { + provider = "sqlite" + url = "***" +} + +model teams { + email String @unique + id Int @id + name String @unique +} + +model variables { + email String + key String + name String + value String + + @@id([name, key]) + @@unique([value, email], name: "sqlite_autoindex_variables_2") +} +` + +exports['a.findOne({ where: { one_two: { one: 1, two: 2 } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource sqlite { + provider = "sqlite" + url = "***" +} + +model teams { + email String @unique + id Int @id + name String @unique +} + +model a { + one Int + two Int + b b[] + + @@id([one, two]) +} + +model b { + id Int @default(autoincrement()) @id + a a @map(["one", "two"]) @relation(references: [one, two]) +} +` + exports['await teams.updateMany({ data: { name: \'b\' }, where: { name: null }, }) client.teams.findMany();'] = ` generator client { provider = "prisma-client-js" @@ -848,3 +1233,26 @@ model teams { name String? } ` + +exports['events.findMany({ where: { time: { lt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } })'] = ` +generator client { + provider = "prisma-client-js" + output = "***" +} + +datasource sqlite { + provider = "sqlite" + url = "***" +} + +model teams { + email String @unique + id Int @id + name String @unique +} + +model events { + id Int @default(autoincrement()) @id + time DateTime? +} +` diff --git a/cli/prisma2/src/__tests__/integrate.mysql.test.ts b/cli/prisma2/src/__tests__/integrate.mysql.test.ts index 7dc5219f18d3..a95dae264f15 100644 --- a/cli/prisma2/src/__tests__/integrate.mysql.test.ts +++ b/cli/prisma2/src/__tests__/integrate.mysql.test.ts @@ -1301,13 +1301,12 @@ function tests(): Test[] { }, }, { - todo: true, up: ` create table events ( id serial not null primary key, - time timestamp with time zone + time datetime ); - insert into events (time) values ('2018-09-04 00:00:00+00'); + insert into events (time) values ('2018-09-04 00:00:00'); `, down: ` drop table if exists events cascade; @@ -1315,99 +1314,94 @@ function tests(): Test[] { do: async client => { return client.events.findMany({ where: { time: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } }) }, - expect: { - id: 1, - token: 10, - }, + expect: [ + { + id: 1, + time: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)), + }, + ], }, { - todo: true, up: ` create table events ( id serial not null primary key, - time timestamp with time zone + time datetime ); - insert into events (time) values ('2018-09-04 00:00:00+00'); + insert into events (time) values ('2018-09-04 00:00:00'); `, down: ` drop table if exists events cascade; `, do: async client => { - return client.events.find({ where: { time: { gt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) - }, - expect: { - id: 1, - token: 10, + return client.events.findMany({ where: { time: { gt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) }, + expect: [], }, { - todo: true, up: ` create table events ( id serial not null primary key, - time timestamp with time zone + time datetime ); - insert into events (time) values ('2018-09-04 00:00:00+00'); + insert into events (time) values ('2018-09-04 00:00:00'); `, down: ` drop table if exists events cascade; `, do: async client => { - return client.events.find({ where: { time: { gte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) - }, - expect: { - id: 1, - token: 10, + return client.events.findMany({ where: { time: { gte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) }, + expect: [ + { + id: 1, + time: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)), + }, + ], }, { - todo: true, up: ` create table events ( id serial not null primary key, - time timestamp with time zone + time datetime ); - insert into events (time) values ('2018-09-04 00:00:00+00'); + insert into events (time) values ('2018-09-04 00:00:00'); `, down: ` drop table if exists events cascade; `, do: async client => { - return client.events.find({ where: { time: { lt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) - }, - expect: { - id: 1, - token: 10, + return client.events.findMany({ where: { time: { lt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) }, + expect: [], }, { - todo: true, up: ` create table events ( id serial not null primary key, - time timestamp with time zone + time datetime ); - insert into events (time) values ('2018-09-04 00:00:00+00'); + insert into events (time) values ('2018-09-04 00:00:00'); `, down: ` drop table if exists events cascade; `, do: async client => { - return client.events.find({ where: { time: { lte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) - }, - expect: { - id: 1, - token: 10, + return client.events.findMany({ where: { time: { lte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) }, + expect: [ + { + id: 1, + time: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)), + }, + ], }, { - todo: true, up: ` create table events ( id serial not null primary key, - time timestamp with time zone + time datetime ); - insert into events (time) values ('2018-09-04 00:00:00+00'); + insert into events (time) values ('2018-09-04 00:00:00'); `, down: ` drop table if exists events cascade; @@ -1415,17 +1409,13 @@ function tests(): Test[] { do: async client => { return client.events.findMany({ where: { time: { not: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) }, - expect: { - id: 1, - token: 10, - }, + expect: [], }, { - todo: true, up: ` create table events ( id serial not null primary key, - time timestamp with time zone + time datetime ); insert into events (time) values (NULL); insert into events (time) values (NULL); @@ -1437,7 +1427,20 @@ function tests(): Test[] { do: async client => { return client.events.findMany({ where: { time: null } }) }, - expect: [], + expect: [ + { + id: 1, + time: null, + }, + { + id: 2, + time: null, + }, + { + id: 3, + time: null, + }, + ], }, { up: ` @@ -1578,7 +1581,7 @@ function tests(): Test[] { expect: [ { email: 'a', - id: 1, + team_id: null, }, ], }, @@ -1682,93 +1685,137 @@ function tests(): Test[] { }, }, { - todo: true, up: ` create table variables ( name varchar(50) not null, - key varchar(50) not null, + \`key\` varchar(50) not null, value varchar(50) not null, email varchar(50) not null, - primary key(name, key) + primary key(name, \`key\`) ); - insert into variables (name, key, value, email) values ('a', 'b', 'c', 'd'); + insert into variables (name, \`key\`, value, email) values ('a', 'b', 'c', 'd'); `, down: ` drop table if exists variables cascade; `, do: async client => { - return client.variables.findOne({ where: { variables_name_key_key: { key: 'b', name: 'a' } } }) + return client.variables.findOne({ where: { name_key: { key: 'b', name: 'a' } } }) + }, + expect: { + email: 'd', + key: 'b', + name: 'a', + value: 'c', }, - expect: {}, // TODO }, { - todo: true, up: ` create table variables ( name varchar(50) not null, - key varchar(50) not null, + \`key\` varchar(50) not null, value varchar(50) not null, email varchar(50) not null, - primary key(name, key) + primary key(name, \`key\`) ); - insert into variables (name, key, value, email) values ('a', 'b', 'c', 'd'); + insert into variables (name, \`key\`, value, email) values ('a', 'b', 'c', 'd'); `, down: ` drop table if exists variables cascade; `, do: async client => { return client.variables.update({ - where: { variables_name_key_key: { key: 'b', name: 'a' } }, + where: { name_key: { key: 'b', name: 'a' } }, data: { email: 'e' }, }) }, - expect: {}, // TODO + expect: { + email: 'e', + key: 'b', + name: 'a', + value: 'c', + }, + }, + { + up: ` + create table variables ( + name varchar(50) not null, + \`key\` varchar(50) not null, + value varchar(50) not null, + email varchar(50) not null, + primary key(name, \`key\`) + ); + insert into variables (name, \`key\`, value, email) values ('a', 'b', 'c', 'd'); + `, + down: ` + drop table if exists variables cascade; + `, + do: async client => { + return client.variables.upsert({ + where: { name_key: { key: 'b', name: 'a' } }, + create: { name: '1', key: '2', value: '3', email: '4' }, + update: { email: 'e' }, + }) + }, + expect: { + email: 'e', + key: 'b', + name: 'a', + value: 'c', + }, }, { - todo: true, up: ` create table variables ( name varchar(50) not null, - key varchar(50) not null, + \`key\` varchar(50) not null, value varchar(50) not null, email varchar(50) not null, - primary key(name, key) + primary key(name, \`key\`) ); - insert into variables (name, key, value, email) values ('a', 'b', 'c', 'd'); + insert into variables (name, \`key\`, value, email) values ('a', 'b', 'c', 'd'); `, down: ` drop table if exists variables cascade; `, do: async client => { return client.variables.upsert({ - where: { variables_name_key_key: { key: 'b', name: 'a' } }, - create: {}, // TODO - update: {}, // TODO + where: { name_key: { key: 'd', name: 'a' } }, + create: { name: '1', key: '2', value: '3', email: '4' }, + update: { email: 'e' }, }) }, - expect: {}, // TODO + expect: { + email: '4', + key: '2', + name: '1', + value: '3', + }, }, { - todo: true, up: ` create table variables ( name varchar(50) not null, - key varchar(50) not null, + \`key\` varchar(50) not null, value varchar(50) not null, email varchar(50) not null, - primary key(name, key) + primary key(name, \`key\`) ); - insert into variables (name, key, value, email) values ('a', 'b', 'c', 'd'); + insert into variables (name, \`key\`, value, email) values ('a', 'b', 'c', 'd'); `, down: ` drop table if exists variables cascade; `, do: async client => { return client.variables.delete({ - where: { variables_name_key_key: { key: 'b', name: 'a' } }, + where: { name_key: { key: 'b', name: 'a' } }, }) }, - expect: {}, // TODO + expect: { + email: 'd', + key: 'b', + name: 'a', + value: 'c', + }, }, { up: ` @@ -1862,7 +1909,7 @@ function tests(): Test[] { drop table if exists crazy cascade; `, do: async client => { - return client.crazy.findOne({ where: { variables_value_email_key: { value: 'c', email: 'd' } } }) + return client.crazy.findOne({ where: { value_email: { value: 'c', email: 'd' } } }) }, expect: { // TODO diff --git a/cli/prisma2/src/__tests__/integrate.postgresql.test.ts b/cli/prisma2/src/__tests__/integrate.postgresql.test.ts index 618fb81da548..fed8b5657f79 100644 --- a/cli/prisma2/src/__tests__/integrate.postgresql.test.ts +++ b/cli/prisma2/src/__tests__/integrate.postgresql.test.ts @@ -1222,7 +1222,6 @@ function tests(): Test[] { ], }, { - // todo: true, up: ` create table posts ( id serial primary key not null, @@ -1242,7 +1241,6 @@ function tests(): Test[] { expect: [], }, { - // todo: true, up: ` create table posts ( id serial primary key not null, @@ -1262,7 +1260,6 @@ function tests(): Test[] { expect: [], }, { - // todo: true, up: ` create table posts ( id serial primary key not null, @@ -1300,7 +1297,6 @@ function tests(): Test[] { ], }, { - todo: true, up: ` create table teams ( id serial primary key not null, @@ -1320,7 +1316,6 @@ function tests(): Test[] { }, }, { - todo: true, up: ` create table events ( id serial not null primary key, @@ -1334,13 +1329,14 @@ function tests(): Test[] { do: async client => { return client.events.findMany({ where: { time: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } }) }, - expect: { - id: 1, - token: 10, - }, + expect: [ + { + id: 1, + time: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)), + }, + ], }, { - todo: true, up: ` create table events ( id serial not null primary key, @@ -1352,15 +1348,11 @@ function tests(): Test[] { drop table if exists events cascade; `, do: async client => { - return client.events.find({ where: { time: { gt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) - }, - expect: { - id: 1, - token: 10, + return client.events.findMany({ where: { time: { gt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) }, + expect: [], }, { - todo: true, up: ` create table events ( id serial not null primary key, @@ -1372,15 +1364,16 @@ function tests(): Test[] { drop table if exists events cascade; `, do: async client => { - return client.events.find({ where: { time: { gte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) - }, - expect: { - id: 1, - token: 10, + return client.events.findMany({ where: { time: { gte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) }, + expect: [ + { + id: 1, + time: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)), + }, + ], }, { - todo: true, up: ` create table events ( id serial not null primary key, @@ -1392,15 +1385,11 @@ function tests(): Test[] { drop table if exists events cascade; `, do: async client => { - return client.events.find({ where: { time: { lt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) - }, - expect: { - id: 1, - token: 10, + return client.events.findMany({ where: { time: { lt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) }, + expect: [], }, { - todo: true, up: ` create table events ( id serial not null primary key, @@ -1412,15 +1401,16 @@ function tests(): Test[] { drop table if exists events cascade; `, do: async client => { - return client.events.find({ where: { time: { lte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) - }, - expect: { - id: 1, - token: 10, + return client.events.findMany({ where: { time: { lte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) }, + expect: [ + { + id: 1, + time: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)), + }, + ], }, { - todo: true, up: ` create table events ( id serial not null primary key, @@ -1434,13 +1424,9 @@ function tests(): Test[] { do: async client => { return client.events.findMany({ where: { time: { not: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) }, - expect: { - id: 1, - token: 10, - }, + expect: [], }, { - todo: true, up: ` create table events ( id serial not null primary key, @@ -1456,7 +1442,20 @@ function tests(): Test[] { do: async client => { return client.events.findMany({ where: { time: null } }) }, - expect: [], + expect: [ + { + id: 1, + time: null, + }, + { + id: 2, + time: null, + }, + { + id: 3, + time: null, + }, + ], }, { up: ` @@ -1596,8 +1595,9 @@ function tests(): Test[] { }, expect: [ { - email: 'a', id: 1, + email: 'a', + team_id: null, }, ], }, @@ -1701,7 +1701,6 @@ function tests(): Test[] { }, }, { - todo: true, up: ` create table variables ( name text not null, @@ -1716,12 +1715,16 @@ function tests(): Test[] { drop table if exists variables cascade; `, do: async client => { - return client.variables.findOne({ where: { variables_name_key_key: { key: 'b', name: 'a' } } }) + return client.variables.findOne({ where: { name_key: { key: 'b', name: 'a' } } }) + }, + expect: { + email: 'd', + key: 'b', + name: 'a', + value: 'c', }, - expect: {}, // TODO }, { - todo: true, up: ` create table variables ( name text not null, @@ -1737,14 +1740,18 @@ function tests(): Test[] { `, do: async client => { return client.variables.update({ - where: { variables_name_key_key: { key: 'b', name: 'a' } }, + where: { name_key: { key: 'b', name: 'a' } }, data: { email: 'e' }, }) }, - expect: {}, // TODO + expect: { + email: 'e', + key: 'b', + name: 'a', + value: 'c', + }, }, { - todo: true, up: ` create table variables ( name text not null, @@ -1760,15 +1767,47 @@ function tests(): Test[] { `, do: async client => { return client.variables.upsert({ - where: { variables_name_key_key: { key: 'b', name: 'a' } }, - create: {}, // TODO - update: {}, // TODO + where: { name_key: { key: 'b', name: 'a' } }, + create: { name: '1', key: '2', value: '3', email: '4' }, + update: { email: 'e' }, }) }, - expect: {}, // TODO + expect: { + email: 'e', + key: 'b', + name: 'a', + value: 'c', + }, + }, + { + up: ` + create table variables ( + name text not null, + key text not null, + value text not null, + email text not null, + primary key(name, key) + ); + insert into variables (name, key, value, email) values ('a', 'b', 'c', 'd'); + `, + down: ` + drop table if exists variables cascade; + `, + do: async client => { + return client.variables.upsert({ + where: { name_key: { key: 'd', name: 'a' } }, + create: { name: '1', key: '2', value: '3', email: '4' }, + update: { email: 'e' }, + }) + }, + expect: { + email: '4', + key: '2', + name: '1', + value: '3', + }, }, { - todo: true, up: ` create table variables ( name text not null, @@ -1784,10 +1823,15 @@ function tests(): Test[] { `, do: async client => { return client.variables.delete({ - where: { variables_name_key_key: { key: 'b', name: 'a' } }, + where: { name_key: { key: 'b', name: 'a' } }, }) }, - expect: {}, // TODO + expect: { + email: 'd', + key: 'b', + name: 'a', + value: 'c', + }, }, { up: ` @@ -2052,7 +2096,7 @@ function tests(): Test[] { drop table if exists crazy cascade; `, do: async client => { - return client.crazy.findOne({ where: { variables_value_email_key: { value: 'c', email: 'd' } } }) + return client.crazy.findOne({ where: { value_email: { value: 'c', email: 'd' } } }) }, expect: { // TODO diff --git a/cli/prisma2/src/__tests__/integrate.sqlite.test.ts b/cli/prisma2/src/__tests__/integrate.sqlite.test.ts index 92c11a3a1ec9..52d3ad5f94ed 100644 --- a/cli/prisma2/src/__tests__/integrate.sqlite.test.ts +++ b/cli/prisma2/src/__tests__/integrate.sqlite.test.ts @@ -997,17 +997,15 @@ function tests(): Test[] { ], }, { - todo: true, - // Empty result with created_at datetime not null DEFAULT CURRENT_TIMESTAMP up: ` create table posts ( id integer primary key not null, title varchar(50) not null, - created_at timestamp not null default now() + created_at datetime not null default current_timestamp ); - insert into posts ("title", "created_at") values ('A', '2020-01-14T11:10:19.573Z'); - insert into posts ("title", "created_at") values ('B', '2020-01-14T11:10:19.573Z'); - insert into posts ("title", "created_at") values ('C', '2020-01-14T11:10:19.573Z'); + insert into posts ("title", "created_at") values ('A', '1579000219573'); + insert into posts ("title", "created_at") values ('B', '1579000219573'); + insert into posts ("title", "created_at") values ('C', '1579000219573'); `, down: ` drop table if exists posts; @@ -1037,16 +1035,15 @@ function tests(): Test[] { ], }, { - todo: true, up: ` create table posts ( id integer primary key not null, title varchar(50) not null, - created_at timestamp not null default now() + created_at datetime not null default current_timestamp ); - insert into posts ("title", "created_at") values ('A', '2020-01-14T11:10:19.573Z'); - insert into posts ("title", "created_at") values ('B', '2020-01-14T11:10:19.573Z'); - insert into posts ("title", "created_at") values ('C', '2020-01-14T11:10:19.573Z'); + insert into posts ("title", "created_at") values ('A', '1579000219573'); + insert into posts ("title", "created_at") values ('B', '1579000219573'); + insert into posts ("title", "created_at") values ('C', '1579000219573'); `, down: ` drop table if exists posts; @@ -1057,16 +1054,15 @@ function tests(): Test[] { expect: [], }, { - todo: true, up: ` create table posts ( id integer primary key not null, title varchar(50) not null, - created_at timestamp not null default now() + created_at datetime not null default current_timestamp ); - insert into posts ("title", "created_at") values ('A', '2020-01-14T11:10:19.573Z'); - insert into posts ("title", "created_at") values ('B', '2020-01-14T11:10:19.573Z'); - insert into posts ("title", "created_at") values ('C', '2020-01-14T11:10:19.573Z'); + insert into posts ("title", "created_at") values ('A', '1579000219573'); + insert into posts ("title", "created_at") values ('B', '1579000219573'); + insert into posts ("title", "created_at") values ('C', '1579000219573'); `, down: ` drop table if exists posts; @@ -1077,16 +1073,15 @@ function tests(): Test[] { expect: [], }, { - todo: true, up: ` create table posts ( id integer primary key not null, title varchar(50) not null, - created_at timestamp not null default now() + created_at datetime not null default current_timestamp ); - insert into posts ("title", "created_at") values ('A', '2020-01-14T11:10:19.573Z'); - insert into posts ("title", "created_at") values ('B', '2020-01-14T11:10:19.573Z'); - insert into posts ("title", "created_at") values ('C', '2020-01-14T11:10:19.573Z'); + insert into posts ("title", "created_at") values ('A', '1579000219573'); + insert into posts ("title", "created_at") values ('B', '1579000219573'); + insert into posts ("title", "created_at") values ('C', '1579000219573'); `, down: ` drop table if exists posts; @@ -1134,116 +1129,107 @@ function tests(): Test[] { }, }, { - todo: true, up: ` create table events ( id integer not null primary key, - "time" timestamp with time zone + "time" datetime ); - insert into events ("time") values ('2018-09-04 00:00:00+00'); + insert into events ("time") values (1536019200000); `, down: ` drop table if exists events; `, do: async client => { - return client.events.findMany({ where: { time: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } }) - }, - expect: { - id: 1, - token: 10, + return await client.events.findMany({ where: { time: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } }) }, + expect: [ + { + id: 1, + time: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)), + }, + ], }, { - todo: true, - // TypeError: client.events.find is not a function up: ` create table events ( id integer not null primary key, - "time" timestamp with time zone + "time" datetime ); - insert into events ("time") values ('2018-09-04 00:00:00+00'); + insert into events ("time") values (1536019200000); `, down: ` drop table if exists events; `, do: async client => { - return client.events.find({ where: { time: { gt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) - }, - expect: { - id: 1, - token: 10, + return client.events.findMany({ where: { time: { gt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) }, + expect: [], }, { - todo: true, - // TypeError: client.events.find is not a function up: ` create table events ( id integer not null primary key, - "time" timestamp with time zone + "time" datetime ); - insert into events ("time") values ('2018-09-04 00:00:00+00'); + insert into events ("time") values (1536019200000); `, down: ` drop table if exists events; `, do: async client => { - return client.events.find({ where: { time: { gte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) - }, - expect: { - id: 1, - token: 10, + return client.events.findMany({ where: { time: { gte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) }, + expect: [ + { + id: 1, + time: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)), + }, + ], }, { - todo: true, - // TypeError: client.events.find is not a function up: ` create table events ( id integer not null primary key, - "time" timestamp with time zone + "time" datetime ); - insert into events ("time") values ('2018-09-04 00:00:00+00'); + insert into events ("time") values (1536019200000); `, down: ` drop table if exists events; `, do: async client => { - return client.events.find({ where: { time: { lt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) - }, - expect: { - id: 1, - token: 10, + return client.events.findMany({ where: { time: { lt: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) }, + expect: [], }, { - todo: true, - // TypeError: client.events.find is not a function up: ` create table events ( id integer not null primary key, - "time" timestamp with time zone + "time" datetime ); - insert into events ("time") values ('2018-09-04 00:00:00+00'); + insert into events ("time") values (1536019200000); `, down: ` drop table if exists events; `, do: async client => { - return client.events.find({ where: { time: { lte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) - }, - expect: { - id: 1, - token: 10, + return client.events.findMany({ where: { time: { lte: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) }, + expect: [ + { + id: 1, + time: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)), + }, + ], }, { up: ` create table events ( id integer not null primary key, - "time" timestamp with time zone + "time" datetime ); - insert into events ("time") values ('2018-09-04 00:00:00+00'); + insert into events ("time") values (1536019200000); `, down: ` drop table if exists events; @@ -1251,19 +1237,14 @@ function tests(): Test[] { do: async client => { return client.events.findMany({ where: { time: { not: new Date(Date.UTC(2018, 8, 4, 0, 0, 0, 0)) } } }) }, - expect: [ - { - id: 1, - time: '2018-09-04 00:00:00+00', - }, - ], + expect: [], }, { todo: true, up: ` create table events ( id integer not null primary key, - "time" timestamp with time zone + "time" datetime ); insert into events ("time") values (NULL); insert into events ("time") values (NULL); @@ -1275,7 +1256,20 @@ function tests(): Test[] { do: async client => { return client.events.findMany({ where: { time: null } }) }, - expect: [], + expect: [ + { + id: 1, + time: null, + }, + { + id: 2, + time: null, + }, + { + id: 3, + time: null, + }, + ], }, { up: ` @@ -1390,6 +1384,7 @@ function tests(): Test[] { ], }, { + todo: true, up: ` pragma foreign_keys = 1; create table teams ( @@ -1416,7 +1411,7 @@ function tests(): Test[] { expect: [ { email: 'a', - id: 1, + team_id: null, }, ], }, @@ -1518,112 +1513,155 @@ function tests(): Test[] { }, }, { - todo: true, up: ` create table variables ( name varchar(50) not null, - key varchar(50) not null, + \`key\` varchar(50) not null, value varchar(50) not null, email varchar(50) not null, - primary key(name, key) + primary key(name, \`key\`) ); - insert into variables (name, key, value, email) values ('a', 'b', 'c', 'd'); + insert into variables (name, \`key\`, value, email) values ('a', 'b', 'c', 'd'); `, down: ` drop table if exists variables; `, do: async client => { - return client.variables.findOne({ where: { variables_name_key_key: { key: 'b', name: 'a' } } }) + return client.variables.findOne({ where: { name_key: { key: 'b', name: 'a' } } }) + }, + expect: { + email: 'd', + key: 'b', + name: 'a', + value: 'c', }, - expect: {}, // TODO }, { - todo: true, up: ` create table variables ( name varchar(50) not null, - key varchar(50) not null, + \`key\` varchar(50) not null, value varchar(50) not null, email varchar(50) not null, - primary key(name, key) + primary key(name, \`key\`) ); - insert into variables (name, key, value, email) values ('a', 'b', 'c', 'd'); + insert into variables (name, \`key\`, value, email) values ('a', 'b', 'c', 'd'); `, down: ` drop table if exists variables; `, do: async client => { return client.variables.update({ - where: { variables_name_key_key: { key: 'b', name: 'a' } }, + where: { name_key: { key: 'b', name: 'a' } }, data: { email: 'e' }, }) }, - expect: {}, // TODO + expect: { + email: 'e', + key: 'b', + name: 'a', + value: 'c', + }, + }, + { + up: ` + create table variables ( + name varchar(50) not null, + \`key\` varchar(50) not null, + value varchar(50) not null, + email varchar(50) not null, + primary key(name, \`key\`) + ); + insert into variables (name, \`key\`, value, email) values ('a', 'b', 'c', 'd'); + `, + down: ` + drop table if exists variables; + `, + do: async client => { + return client.variables.upsert({ + where: { name_key: { key: 'b', name: 'a' } }, + create: { name: '1', key: '2', value: '3', email: '4' }, + update: { email: 'e' }, + }) + }, + expect: { + email: 'e', + key: 'b', + name: 'a', + value: 'c', + }, }, { - todo: true, up: ` create table variables ( name varchar(50) not null, - key varchar(50) not null, + \`key\` varchar(50) not null, value varchar(50) not null, email varchar(50) not null, - primary key(name, key) + primary key(name, \`key\`) ); - insert into variables (name, key, value, email) values ('a', 'b', 'c', 'd'); + insert into variables (name, \`key\`, value, email) values ('a', 'b', 'c', 'd'); `, down: ` drop table if exists variables; `, do: async client => { return client.variables.upsert({ - where: { variables_name_key_key: { key: 'b', name: 'a' } }, - create: {}, // TODO - update: {}, // TODO + where: { name_key: { key: 'd', name: 'a' } }, + create: { name: '1', key: '2', value: '3', email: '4' }, + update: { email: 'e' }, }) }, - expect: {}, // TODO + expect: { + email: '4', + key: '2', + name: '1', + value: '3', + }, }, { - todo: true, up: ` create table variables ( name varchar(50) not null, - key varchar(50) not null, + \`key\` varchar(50) not null, value varchar(50) not null, email varchar(50) not null, - primary key(name, key) + primary key(name, \`key\`) ); - insert into variables (name, key, value, email) values ('a', 'b', 'c', 'd'); + insert into variables (name, \`key\`, value, email) values ('a', 'b', 'c', 'd'); `, down: ` drop table if exists variables; `, do: async client => { return client.variables.delete({ - where: { variables_name_key_key: { key: 'b', name: 'a' } }, + where: { name_key: { key: 'b', name: 'a' } }, }) }, - expect: {}, // TODO + expect: { + email: 'd', + key: 'b', + name: 'a', + value: 'c', + }, }, { - todo: true, up: ` create table variables ( id integer primary key not null, name varchar(50) not null, - key varchar(50) not null, + \`key\` varchar(50) not null, value varchar(50) not null, email varchar(50) not null, - unique(name, key) + unique(name, \`key\`) ); - insert into variables (name, key, value, email) values ('a', 'b', 'c', 'd'); + insert into variables (name, \`key\`, value, email) values ('a', 'b', 'c', 'd'); `, down: ` drop table if exists variables; `, do: async client => { - return client.variables.findOne({ where: { variables_name_key_key: { key: 'b', name: 'a' } } }) + return client.variables.findOne({ where: { sqlite_autoindex_variables_1: { key: 'b', name: 'a' } } }) }, expect: { email: 'd', @@ -1634,23 +1672,22 @@ function tests(): Test[] { }, }, { - todo: true, up: ` create table variables ( name varchar(50) not null, - key varchar(50) not null, + \`key\` varchar(50) not null, value varchar(50) not null, email varchar(50) not null, - primary key(name, key), + primary key(name, \`key\`), unique(value, email) ); - insert into variables (name, key, value, email) values ('a', 'b', 'c', 'd'); + insert into variables (name, \`key\`, value, email) values ('a', 'b', 'c', 'd'); `, down: ` drop table if exists variables; `, do: async client => { - return client.variables.findOne({ where: { variables_value_email_key: { value: 'c', email: 'd' } } }) + return client.variables.findOne({ where: { sqlite_autoindex_variables_2: { value: 'c', email: 'd' } } }) }, expect: { email: 'd', @@ -1660,8 +1697,6 @@ function tests(): Test[] { }, }, { - todo: true, - //SqliteError: FOREIGN KEY constraint failed up: ` pragma foreign_keys = 1; create table a ( @@ -1670,7 +1705,7 @@ function tests(): Test[] { primary key ("one", "two") ); create table b ( - id integer primary key autoincrement not null, + id integer primary key not null, one integer not null, two integer not null, foreign key ("one", "two") references a ("one", "two")