about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-03-06 19:55:18 +0100
committerEmile <hanemile@protonmail.com>2019-03-06 19:55:18 +0100
commitac0afbf77f17adc569ea2787a52776f80ff78737 (patch)
treef04d47697108d6bc9633e21e1e3e8a2ae441c65f
parent70a98048d920d0e571a46a7d9ff104a70188dca0 (diff)
added a function creating a stars table and a function creating a nodes table
-rw-r--r--db_actions.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/db_actions.go b/db_actions.go
index 26d9b59..a45c562 100644
--- a/db_actions.go
+++ b/db_actions.go
@@ -1277,3 +1277,55 @@ func calcForce(s1 structs.Star2D, s2 structs.Star2D) structs.Vec2 {
 	// return the force exerted on s1 by s2
 	return force
 }
+
+func InitStarsTable(db *sql.DB) {
+	query := `CREATE TABLE public.stars
+(
+    star_id bigint NOT NULL DEFAULT nextval('stars_star_id_seq'::regclass),
+    x numeric,
+    y numeric,
+    vx numeric,
+    vy numeric,
+    m numeric
+)
+WITH (
+    OIDS = FALSE
+)
+TABLESPACE pg_default;
+
+ALTER TABLE public.stars
+    OWNER to postgres;
+`
+	err := db.QueryRow(query)
+	if err != nil {
+		log.Fatalf("[ E ] InitNodesTable query: %v \n\t\t\tquery: %s\n", err, query)
+	}
+}
+
+func InitNodesTable(db *sql.DB) {
+	query := `CREATE TABLE public.nodes
+	(
+		node_id bigint NOT NULL DEFAULT nextval('nodes_node_id_seq'::regclass),
+	box_width numeric NOT NULL,
+		total_mass numeric NOT NULL,
+		depth integer,
+		star_id bigint NOT NULL,
+		root_id bigint NOT NULL,
+		isleaf boolean,
+		box_center numeric[] NOT NULL,
+		center_of_mass numeric[] NOT NULL,
+		subnodes bigint[] NOT NULL
+	)
+	WITH (
+		OIDS = FALSE
+	)
+	TABLESPACE pg_default;
+
+	ALTER TABLE public.nodes
+	OWNER to postgres;
+`
+	err := db.QueryRow(query)
+	if err != nil {
+		log.Fatalf("[ E ] InitNodesTable query: %v \n\t\t\tquery: %s\n", err, query)
+	}
+}