Skip to content

Commit

Permalink
add point support
Browse files Browse the repository at this point in the history
  • Loading branch information
jairad26 committed Dec 12, 2024
1 parent c0a1aad commit 19a25f0
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 7 deletions.
6 changes: 3 additions & 3 deletions sdk/assemblyscript/examples/neo4j/assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export function CreatePeopleAndRelationships(): string {
for (let i = 0; i < people.length; i++) {
const createPersonQuery = `
MATCH (p:Person {name: $person.name})
UNWIND $person.friends AS friend_name
MATCH (friend:Person {name: friend_name})
MERGE (p)-[:KNOWS]->(friend)
UNWIND $person.friends AS friend_name
MATCH (friend:Person {name: friend_name})
MERGE (p)-[:KNOWS]->(friend)
`;
const peopleVars = new neo4j.Variables();
peopleVars.set("person", people[i]);
Expand Down
52 changes: 50 additions & 2 deletions sdk/assemblyscript/src/assembly/neo4j.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ export class Record {
idof<T>() === idof<u64[]>() ||
idof<T>() === idof<f32[]>() ||
idof<T>() === idof<f64[]>() ||
idof<T>() === idof<Date>()
idof<T>() === idof<Date>() ||
idof<T>() === idof<JSON.Raw>() ||
idof<T>() === idof<Point2D>() ||
idof<T>() === idof<Point3D>()
) {
for (let i = 0; i < this.Keys.length; i++) {
if (this.Keys[i] == key) {
Expand Down Expand Up @@ -120,7 +123,16 @@ abstract class Entity {
Props!: DynamicMap;

getProperty<T>(key: string): T {
if (isInteger<T>() || isFloat<T>() || isBoolean<T>() || isString<T>()) {
if (
isInteger<T>() ||
isFloat<T>() ||
isBoolean<T>() ||
isString<T>() ||
idof<T>() === idof<Date>() ||
idof<T>() === idof<JSON.Raw>() ||
idof<T>() === idof<Point2D>() ||
idof<T>() === idof<Point3D>()
) {
return this.Props.get<T>(key);
}
throw new Error("Unsupported type.");
Expand Down Expand Up @@ -162,3 +174,39 @@ export class Path {
@alias("Relationships")
Relationships!: Relationship[];
}


@json
export class Point2D {

@alias("X")
X!: f64;


@alias("Y")
Y!: f64;


@alias("SpatialRefId")
SpatialRefId!: u32;
}


@json
export class Point3D {

@alias("X")
X!: f64;


@alias("Y")
Y!: f64;


@alias("Z")
Z!: f64;


@alias("SpatialRefId")
SpatialRefId!: u32;
}
29 changes: 27 additions & 2 deletions sdk/go/pkg/neo4j/neo4j.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type RecordValue interface {
bool | int64 | float64 | string |
time.Time |
[]byte | []any | map[string]any |
Node | Relationship | Path
Node | Relationship | Path | Point2D | Point3D
}

type Entity interface {
Expand Down Expand Up @@ -88,7 +88,32 @@ type Path struct {

type PropertyValue interface {
bool | int64 | float64 | string |
time.Time | []byte | []any
time.Time | []byte | []any | Point2D | Point3D
}

// Point2D represents a two dimensional point in a particular coordinate reference system.
type Point2D struct {
X float64
Y float64
SpatialRefId uint32 // Id of coordinate reference system.
}

// Point3D represents a three dimensional point in a particular coordinate reference system.
type Point3D struct {
X float64
Y float64
Z float64
SpatialRefId uint32 // Id of coordinate reference system.
}

// String returns string representation of this point.
func (p Point2D) String() string {
return fmt.Sprintf("Point{SpatialRefId=%d, X=%f, Y=%f}", p.SpatialRefId, p.X, p.Y)
}

// String returns string representation of this point.
func (p Point3D) String() string {
return fmt.Sprintf("Point{SpatialRefId=%d, X=%f, Y=%f, Z=%f}", p.SpatialRefId, p.X, p.Y, p.Z)
}

/**
Expand Down

0 comments on commit 19a25f0

Please sign in to comment.