Repository: surrealdb/surrealdb.go (go)

Issue:
Bug:  GeometryPoint lat/lng swap issue
### Describe the bug

When viewing the coordinates in Surrealist, it would appear as if the coordinates are the wrong way around. I assume this is an issue with the GO SDK.

From what I understand from the docs, GeometryPoint is (longitude, latitude) https://surrealdb.com/docs/surrealql/datamodel/geometries#point

Yet when I create a record with the correct cooirdinates via GO SDK, when I view the geometry map within Surrealist e.g. Geography explorer, it's in the wrong location. I have to flip the coordinates in order to get it to work.

### Steps to reproduce

```
package main

import (
	"fmt"
	"log"

	"github.com/surrealdb/surrealdb.go"
	"github.com/surrealdb/surrealdb.go/pkg/models"
)

// Location represents a geographic location
type Location struct {
	ID          *models.RecordID      `json:"id,omitempty"`
	Name        string                `json:"name"`
	Coordinates *models.GeometryPoint `json:"coordinates"`
}

func main() {
	// Connect to SurrealDB
	db, err := surrealdb.New("ws://localhost:8530")
	if err != nil {
		log.Fatalf("Failed to connect to SurrealDB: %v", err)
	}
	defer db.Close()

	// Authenticate (adjust credentials as needed)
	authData := &surrealdb.Auth{
		Username: "root",
		Password: "root",
	}
	if _, err := db.SignIn(authData); err != nil {
		log.Fatalf("Failed to authenticate: %v", err)
	}

	// Use namespace and database
	if err := db.Use("test", "test"); err != nil {
		log.Fatalf("Failed to use namespace/database: %v", err)
	}

	fmt.Println("=== Testing GeometryPoint Coordinate Bug ===")
	fmt.Println()

	// Test Case 1: Create location with standard lat/lng values
	fmt.Println("Test Case 1: Creating location with standard coordinates")
	fmt.Println("---------------------------------------------------")

	london1 := Location{
		Name: "London1",
		Coordinates: &models.GeometryPoint{
			Latitude:  51.5074, // London latitude
			Longitude: -0.1278, // London longitude
		},
	}

	// Create the record
	created, err := surrealdb.Create[Location](db, models.Table("locations"), london1)
	if err != nil {
		log.Fatalf("Failed to create location: %v", err)
	}

	// Test Case 2: Verify the bug by creating with swapped coordinates
	fmt.Println("Test Case 2: Creating location with SWAPPED coordinates (workaround)")
	fmt.Println("-------------------------------------------------------------------")

	london2 := Location{
		Name: "London2",
		Coordinates: &models.GeometryPoint{
			Latitude:  -0.1278, // London longitude
			Longitude: 51.5074, // London latitude
		},
	}

	created2, err := surrealdb.Create[Location](db, models.Table("locations"), london2)
	if err != nil {
		log.Fatalf("Failed to create location: %v", err)
	}

	fmt.Println(created, created2)
}

```

### Expected behaviour

For now I simply just swap them in code, but it's a bit confusing. 

I've tested on the very latest GO SDK 0.3.3.

### SurrealDB version

2.3.6

### Contact Details

_No response_

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Pull request:
Fix incorrect encoding of GeometryPoint
Fixes #223

Patch:
diff --git a/docs/potential_breaking_changes.md b/docs/potential_breaking_changes.md
new file mode 100644
index 0000000..80238fb
--- /dev/null
+++ b/docs/potential_breaking_changes.md
@@ -0,0 +1,7 @@
+# Potential Breaking Changes
+
+This document is supposed to list up findings on and feedbacks to the SDK v0.x that might result in breaking changes if addressed.
+
+Depending on the degree of "breaking", we might address those while in v0, or when cutting v1.
+
+- `NewGeometryPoint` takes the latitude and the longtitude in an order that conflicts with SurrealDB. Based on GeoJSON, SurrealDB assumes the longtitude appear earlier, while `NewGeometryPoint` takes the latitude earlier. TThe function should be changed to take the longtitude earlier. Related issue: #223
diff --git a/pkg/models/geometry.go b/pkg/models/geometry.go
index 1e4f9a4..78adb0e 100644
--- a/pkg/models/geometry.go
+++ b/pkg/models/geometry.go
@@ -18,7 +18,7 @@ func NewGeometryPoint(latitude, longitude float64) GeometryPoint {
 }
 
 func (gp *GeometryPoint) GetCoordinates() [2]float64 {
-	return [2]float64{gp.Latitude, gp.Longitude}
+	return [2]float64{gp.Longitude, gp.Latitude}
 }
 
 func (gp *GeometryPoint) MarshalCBOR() ([]byte, error) {
@@ -34,12 +34,12 @@ func (gp *GeometryPoint) UnmarshalCBOR(data []byte) error {
 		return fmt.Errorf("GeometryPoint: %w", err)
 	}
 
-	var latlon [2]float64
-	if err := cbor.Unmarshal(data, &latlon); err != nil {
+	var lonlat [2]float64
+	if err := cbor.Unmarshal(data, &lonlat); err != nil {
 		return fmt.Errorf("failed to unmarshal GeometryPoint coordinates: %w", err)
 	}
-	gp.Latitude = latlon[0]
-	gp.Longitude = latlon[1]
+	gp.Longitude = lonlat[0]
+	gp.Latitude = lonlat[1]
 
 	return nil
 }


Test patch:
diff --git a/pkg/models/cbor_test.go b/pkg/models/cbor_test.go
index c39f344..16a7666 100644
--- a/pkg/models/cbor_test.go
+++ b/pkg/models/cbor_test.go
@@ -35,7 +35,7 @@ func TestForGeometryPoint(t *testing.T) {
 	err = cbor.Unmarshal(encoded, &decoded3)
 	assert.Nil(t, err, "Should not encounter an error while decoding to any using cbor")
 	assert.IsType(t, cbor.Tag{}, decoded3, "Decoded value should be of type GeometryPoint")
-	assert.Equal(t, cbor.Tag{Number: TagGeometryPoint, Content: []interface{}{12.23, 45.65}}, decoded3)
+	assert.Equal(t, cbor.Tag{Number: TagGeometryPoint, Content: []interface{}{45.65, 12.23}}, decoded3)
 }
 
 func TestForGeometryLine(t *testing.T) {