This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added proper support for Mongo BSON data types.
Added useful errors for type conflicts.
- Loading branch information
1 parent
ea7c5a1
commit 65e99ca
Showing
7 changed files
with
124 additions
and
12 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
cli/packages/prisma-db-introspection/src/__tests__/document/data/mongoTypes.ts
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,52 @@ | ||
import * as BSON from 'bson' | ||
|
||
// Client doc: https://mongodb.github.io/node-mongodb-native/api-bson-generated/bson.html | ||
// Database doc: https://docs.mongodb.com/manual/reference/bson-types/ | ||
export const scalars = [{ | ||
_id: 0, | ||
double: new BSON.Double(0.5), | ||
string: 'string', | ||
object: { test: 'test' }, | ||
array: [1, 2, 3], | ||
binary: new BSON.Binary(new Buffer(5)), | ||
objectId: new BSON.ObjectID(), | ||
boolean: true, | ||
date: new Date(), | ||
null: null, | ||
regex: new BSON.BSONRegExp('\\w', 'i'), | ||
javascript: new BSON.Code('alert("hello")'), | ||
int32: new BSON.Int32(10), | ||
timestamp: new BSON.Timestamp(10, 10), | ||
int64: new BSON.Long(10, 10), | ||
decimal128: new BSON.Decimal128(new Buffer(4)) | ||
}] | ||
|
||
export const schemaString = `type scalars { | ||
# Type Int is currently not supported for id fields. | ||
_id: Int! @id | ||
array: [Int!]! | ||
# Field type not supported: Binary | ||
# binary: <Unknown> | ||
boolean: Boolean | ||
date: DateTime | ||
# Field type not supported: Decimal128 | ||
# decimal128: <Unknown> | ||
double: Float | ||
int32: Int | ||
int64: Int | ||
# Field type not supported: Code | ||
# javascript: <Unknown> | ||
# Field type not supported: null | ||
# null: <Unknown> | ||
object: scalarsObject | ||
objectId: ID | ||
# Field type not supported: RegExp | ||
# regex: <Unknown> | ||
string: String | ||
# Field type not supported: Timestamp | ||
# timestamp: <Unknown> | ||
} | ||
type scalarsObject @embedded { | ||
test: String | ||
}` |
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
21 changes: 21 additions & 0 deletions
21
cli/packages/prisma-db-introspection/src/__tests__/document/mongo/scalarTypes.ts
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,21 @@ | ||
import { MongoConnector } from '../../../databases/document/mongo/mongoConnector' | ||
import { MongoTestEnvironment } from '../../../test-helpers/mongoTestEnvironment' | ||
import { scalars, schemaString } from '../data/mongoTypes' | ||
|
||
const env = new MongoTestEnvironment() | ||
|
||
describe('Mongo Model Introspector, end to end', () => { | ||
beforeAll(async () => await env.connect()) | ||
afterAll(async () => await env.disconnect()) | ||
afterEach(async () => await env.clear()) | ||
|
||
it('Scalar Types', async () => { | ||
await env.createCollections({ scalars }) | ||
|
||
const connector = new MongoConnector(env.getClient()) | ||
const introspection = await connector.introspect(env.schemaName) | ||
const schema = await introspection.renderToDatamodelString() | ||
|
||
expect(schema).toEqual(schemaString) | ||
}, 10000) | ||
}) |
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