From 5924929f0039bdf8a63ac0660e87d58ed930aa52 Mon Sep 17 00:00:00 2001 From: Chris Bonifacio Date: Wed, 15 May 2024 18:15:53 -0400 Subject: [PATCH 1/4] add GEOMFROMTEXT to cspell --- cspell.json | 1 + 1 file changed, 1 insertion(+) diff --git a/cspell.json b/cspell.json index 4309a721428..16992693bb9 100644 --- a/cspell.json +++ b/cspell.json @@ -641,6 +641,7 @@ "Geofences", "Geofencing", "geolocation", + "GEOMFROMTEXT", "geospatial", "getAllKeys", "getApplicationContext", From a3f76eb9b7f9186a66498448f4f80da1475691d4 Mon Sep 17 00:00:00 2001 From: Chris Bonifacio Date: Wed, 15 May 2024 18:17:04 -0400 Subject: [PATCH 2/4] add SRID to cspell --- cspell.json | 1 + 1 file changed, 1 insertion(+) diff --git a/cspell.json b/cspell.json index 16992693bb9..74ec0b47c6d 100644 --- a/cspell.json +++ b/cspell.json @@ -1225,6 +1225,7 @@ "spinner.js", "SQLite", "src", + "SRID", "snstopic", "snstopicemailsub", "SSECustomerAlgorithm", From 205130aef89778504561caa6d8f5ccb6711b8b79 Mon Sep 17 00:00:00 2001 From: Chris Bonifacio Date: Wed, 15 May 2024 18:17:10 -0400 Subject: [PATCH 3/4] add MySQL and PostgreSQL statements for sqlReference example --- .../connect-postgres-mysql-database/index.mdx | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/connect-to-existing-data-sources/connect-postgres-mysql-database/index.mdx b/src/pages/[platform]/build-a-backend/data/connect-to-existing-data-sources/connect-postgres-mysql-database/index.mdx index 710ac8bc75d..d5f155f9b7f 100644 --- a/src/pages/[platform]/build-a-backend/data/connect-to-existing-data-sources/connect-postgres-mysql-database/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/connect-to-existing-data-sources/connect-postgres-mysql-database/index.mdx @@ -99,7 +99,7 @@ If your RDS database exists within a VPC, it must be configured to be `Publicly **To generate the TypeScript representation of your database schema:** -If your database is protected by a VPC, you will need to add an **Inbound Rule** for the database port from your local IP address. The `npx ampx generate schema-from-database` command connects to your database from your local workstation to read schema information. +If your database is protected by a VPC, you will need to add an **Inbound Rule** for the database port from your local IP address. The `npx ampx generate schema-from-database` command connects to your database from your local workstation to read schema information. If you are connecting to an RDS Proxy, the machine you run the `generate schema-from-database` command must be in the same VPC as the proxy itself, or you must connect to it via VPN. Simply opening an **Inbound Rule** for the database port is not sufficient. @@ -165,7 +165,7 @@ const combinedSchema = a.combine([schema, sqlSchema]); export type Schema = ClientSchema; export const data = defineData({ - // Update the data definition to use the combined schema, instead of just + // Update the data definition to use the combined schema, instead of just // your DynamoDB-backed schema // highlight-next-line schema: combinedSchema @@ -222,7 +222,7 @@ const sqlSchema = generatedSqlSchema.authorization(allow => allow.guest()) .renameModels(() => [ //⌄⌄⌄⌄⌄ existing model name based on table name ['event', 'Event'] - // ^^^^^^ renamed data model name + // ^^^^^^ renamed data model name ]) // highlight-end ``` @@ -250,7 +250,7 @@ Use the `.addToSchema(...)` to add in additional queries, mutations, and subscri -Note: you can't add additional data models via `a.model()`. They should be exclusively generated via `npx ampx generate schema-from-database`. +Note: you can't add additional data models via `a.model()`. They should be exclusively generated via `npx ampx generate schema-from-database`. @@ -262,7 +262,7 @@ const sqlSchema = generatedSqlSchema.authorization(allow => allow.guest()) // highlight-start .addToSchema({ listEventsWithDecodedLatLong: a.query() - // reference custom types added to the schema + // reference custom types added to the schema .returns(a.ref("EventWithDecodedCoord").array()) .handler(a.handler.inlineSql( `SELECT @@ -311,8 +311,21 @@ const sqlSchema = generatedSqlSchema.authorization(allow => allow.guest()) ``` Next, add a corresponding sql file to handle the request: -```sql + + + +```sql title="createNewLocationWithLongLat.sql" +INSERT INTO locations (name, address, geom) +VALUES (:name, :address, ST_GEOMFROMTEXT(CONCAT('POINT (', :long, ' ', :lat, ')'))); +``` + + +```sql title="createNewLocationWithLongLat.sql" +INSERT INTO locations (name, address, geom) +VALUES (:name, :address, ST_SetSRID(ST_MakePoint(:long, :lat), 4326)) ``` + + ## How does it work? From b764e803c551122e8edc6129b2a306931a210808 Mon Sep 17 00:00:00 2001 From: Chris Bonifacio Date: Wed, 15 May 2024 18:58:38 -0400 Subject: [PATCH 4/4] add SRID to MySQL example --- .../connect-postgres-mysql-database/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/data/connect-to-existing-data-sources/connect-postgres-mysql-database/index.mdx b/src/pages/[platform]/build-a-backend/data/connect-to-existing-data-sources/connect-postgres-mysql-database/index.mdx index d5f155f9b7f..57cd905f8b4 100644 --- a/src/pages/[platform]/build-a-backend/data/connect-to-existing-data-sources/connect-postgres-mysql-database/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/connect-to-existing-data-sources/connect-postgres-mysql-database/index.mdx @@ -316,7 +316,7 @@ Next, add a corresponding sql file to handle the request: ```sql title="createNewLocationWithLongLat.sql" INSERT INTO locations (name, address, geom) -VALUES (:name, :address, ST_GEOMFROMTEXT(CONCAT('POINT (', :long, ' ', :lat, ')'))); +VALUES (:name, :address, ST_GEOMFROMTEXT(CONCAT('POINT (', :long, ' ', :lat, ')'), 4326)); ```