Skip to content

Commit

Permalink
Merge branch 'main' into feat/ga-fullTextSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
jkomyno authored Nov 26, 2024
2 parents 3062ae2 + 4180c29 commit 69e3182
Show file tree
Hide file tree
Showing 18 changed files with 284 additions and 2 deletions.
9 changes: 9 additions & 0 deletions prisma-fmt/src/get_datamodel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ mod tests {
{
"name": "User",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand All @@ -74,6 +75,7 @@ mod tests {
"isReadOnly": false,
"hasDefaultValue": true,
"type": "Int",
"nativeType": null,
"default": {
"name": "autoincrement",
"args": []
Expand All @@ -91,6 +93,7 @@ mod tests {
"isReadOnly": false,
"hasDefaultValue": false,
"type": "String",
"nativeType": null,
"isGenerated": false,
"isUpdatedAt": false
},
Expand All @@ -104,6 +107,7 @@ mod tests {
"isReadOnly": false,
"hasDefaultValue": false,
"type": "Post",
"nativeType": null,
"relationName": "PostToUser",
"relationFromFields": [],
"relationToFields": [],
Expand All @@ -119,6 +123,7 @@ mod tests {
{
"name": "Post",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand All @@ -130,6 +135,7 @@ mod tests {
"isReadOnly": false,
"hasDefaultValue": true,
"type": "Int",
"nativeType": null,
"default": {
"name": "autoincrement",
"args": []
Expand All @@ -147,6 +153,7 @@ mod tests {
"isReadOnly": false,
"hasDefaultValue": false,
"type": "String",
"nativeType": null,
"isGenerated": false,
"isUpdatedAt": false
},
Expand All @@ -160,6 +167,7 @@ mod tests {
"isReadOnly": false,
"hasDefaultValue": false,
"type": "User",
"nativeType": null,
"relationName": "PostToUser",
"relationFromFields": [
"authorId"
Expand All @@ -180,6 +188,7 @@ mod tests {
"isReadOnly": true,
"hasDefaultValue": false,
"type": "Int",
"nativeType": null,
"isGenerated": false,
"isUpdatedAt": false
}
Expand Down
7 changes: 7 additions & 0 deletions prisma-fmt/src/get_dmmf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ mod tests {
{
"name": "A",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand All @@ -384,6 +385,7 @@ mod tests {
"isReadOnly": false,
"hasDefaultValue": false,
"type": "String",
"nativeType": null,
"isGenerated": false,
"isUpdatedAt": false
},
Expand All @@ -397,6 +399,7 @@ mod tests {
"isReadOnly": true,
"hasDefaultValue": false,
"type": "String",
"nativeType": null,
"isGenerated": false,
"isUpdatedAt": false
},
Expand All @@ -410,6 +413,7 @@ mod tests {
"isReadOnly": false,
"hasDefaultValue": false,
"type": "B",
"nativeType": null,
"relationName": "AToB",
"relationFromFields": [
"b_id"
Expand All @@ -429,6 +433,7 @@ mod tests {
{
"name": "B",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand All @@ -440,6 +445,7 @@ mod tests {
"isReadOnly": false,
"hasDefaultValue": false,
"type": "String",
"nativeType": null,
"isGenerated": false,
"isUpdatedAt": false
},
Expand All @@ -453,6 +459,7 @@ mod tests {
"isReadOnly": false,
"hasDefaultValue": false,
"type": "A",
"nativeType": null,
"relationName": "AToB",
"relationFromFields": [],
"relationToFields": [],
Expand Down
9 changes: 9 additions & 0 deletions query-engine/dmmf/src/ast_builders/datamodel_ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ fn composite_type_to_dmmf(ct: walkers::CompositeTypeWalker<'_>) -> Model {
Model {
name: ct.name().to_owned(),
db_name: None,
schema: None,
fields: ct
.fields()
.filter(|field| !matches!(field.r#type(), ScalarFieldType::Unsupported(_)))
Expand Down Expand Up @@ -94,6 +95,9 @@ fn composite_type_field_to_dmmf(field: walkers::CompositeTypeFieldWalker<'_>) ->
is_id: false,
is_read_only: false,
has_default_value: field.default_value().is_some(),
native_type: field
.raw_native_type()
.map(|(_, name, args, ..)| (name.to_string(), args.to_vec())),
default: field
.default_value()
.map(|dv| default_value_to_serde(&dml_default_kind(dv, field.scalar_type()))),
Expand Down Expand Up @@ -127,6 +131,7 @@ fn model_to_dmmf(model: walkers::ModelWalker<'_>) -> Model {
Model {
name: model.name().to_owned(),
db_name: model.mapped_name().map(ToOwned::to_owned),
schema: model.schema().map(|(s, _)| s.to_owned()),
fields: model
.fields()
.filter(|field| !should_skip_model_field(field))
Expand Down Expand Up @@ -195,6 +200,9 @@ fn scalar_field_to_dmmf(field: walkers::ScalarFieldWalker<'_>) -> Field {
ScalarFieldType::BuiltInScalar(st) => st.as_str().to_owned(),
ScalarFieldType::Unsupported(_) => unreachable!(),
},
native_type: field
.raw_native_type()
.map(|(_, name, args, ..)| (name.to_string(), args.to_vec())),
default: field
.default_value()
.map(|dv| default_value_to_serde(&dml_default_kind(dv.value(), field.scalar_type()))),
Expand All @@ -221,6 +229,7 @@ fn relation_field_to_dmmf(field: walkers::RelationFieldWalker<'_>) -> Field {
is_read_only: false,
has_default_value: false,
field_type: field.related_model().name().to_owned(),
native_type: None,
default: None,
relation_name: Some(field.relation_name().to_string()),
relation_from_fields: Some(
Expand Down
4 changes: 4 additions & 0 deletions query-engine/dmmf/src/serialization_ast/datamodel_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct Field {
#[serde(rename = "type")]
pub field_type: String,

pub native_type: Option<(String, Vec<String>)>,

#[serde(skip_serializing_if = "Option::is_none")]
pub default: Option<serde_json::Value>,

Expand Down Expand Up @@ -62,6 +64,8 @@ pub struct Function {
pub struct Model {
pub name: String,
pub db_name: Option<String>,
pub schema: Option<String>,

pub fields: Vec<Field>,
pub primary_key: Option<PrimaryKey>,
pub unique_fields: Vec<Vec<String>>,
Expand Down
Binary file not shown.
11 changes: 11 additions & 0 deletions query-engine/dmmf/test_files/functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"name": "User",
"dbName": null,
"schema": null,
"fields": [
{
"name": "id",
Expand All @@ -15,6 +16,7 @@
"isReadOnly": false,
"hasDefaultValue": false,
"type": "Int",
"nativeType": null,
"isGenerated": false,
"isUpdatedAt": false
},
Expand All @@ -28,6 +30,7 @@
"isReadOnly": false,
"hasDefaultValue": true,
"type": "DateTime",
"nativeType": null,
"default": {
"name": "now",
"args": []
Expand All @@ -45,6 +48,7 @@
"isReadOnly": false,
"hasDefaultValue": true,
"type": "String",
"nativeType": null,
"default": {
"name": "cuid",
"args": [
Expand All @@ -64,6 +68,7 @@
"isReadOnly": false,
"hasDefaultValue": true,
"type": "String",
"nativeType": null,
"default": {
"name": "cuid",
"args": [
Expand All @@ -83,6 +88,7 @@
"isReadOnly": false,
"hasDefaultValue": true,
"type": "String",
"nativeType": null,
"default": {
"name": "cuid",
"args": [
Expand All @@ -102,6 +108,7 @@
"isReadOnly": false,
"hasDefaultValue": true,
"type": "String",
"nativeType": null,
"default": {
"name": "uuid",
"args": [
Expand All @@ -121,6 +128,7 @@
"isReadOnly": false,
"hasDefaultValue": true,
"type": "String",
"nativeType": null,
"default": {
"name": "uuid",
"args": [
Expand All @@ -140,6 +148,7 @@
"isReadOnly": false,
"hasDefaultValue": true,
"type": "String",
"nativeType": null,
"default": {
"name": "uuid",
"args": [
Expand All @@ -159,6 +168,7 @@
"isReadOnly": false,
"hasDefaultValue": true,
"type": "String",
"nativeType": null,
"default": {
"name": "nanoid",
"args": []
Expand All @@ -176,6 +186,7 @@
"isReadOnly": false,
"hasDefaultValue": true,
"type": "String",
"nativeType": null,
"default": {
"name": "nanoid",
"args": [
Expand Down
Loading

0 comments on commit 69e3182

Please sign in to comment.