From e92bcbc152f82082fd0bf97c920025a9145d748e Mon Sep 17 00:00:00 2001 From: RGGH Date: Wed, 27 Mar 2024 13:36:26 +0000 Subject: [PATCH] relate added --- record_link.surql | 30 +++++ src/controller.rs | 28 +++-- src/db/000583.sst | Bin 0 -> 4338 bytes src/db/CURRENT | 1 + src/db/IDENTITY | 1 + src/db/LOCK | 0 src/db/LOG | 0 src/db/LOG.old.1711536591639406 | 0 src/db/LOG.old.1711536727664902 | 0 src/db/LOG.old.1711536785550446 | 0 src/db/LOG.old.1711536866344950 | 0 src/db/LOG.old.1711537050745744 | 0 src/db/LOG.old.1711538120616679 | 0 src/db/LOG.old.1711538196379150 | 0 src/db/LOG.old.1711538303743359 | 0 src/db/LOG.old.1711538366428099 | 0 src/db/LOG.old.1711538422375930 | 0 src/db/LOG.old.1711539011481882 | 0 src/db/LOG.old.1711539135557810 | 0 src/db/LOG.old.1711539259147523 | 0 src/db/LOG.old.1711539272965806 | 0 src/db/LOG.old.1711539323947710 | 0 src/db/LOG.old.1711542150900978 | 0 src/db/LOG.old.1711542273690477 | 0 src/db/LOG.old.1711542323652174 | 0 src/db/LOG.old.1711542330246917 | 0 src/db/MANIFEST-000580 | Bin 0 -> 1207 bytes src/db/OPTIONS-000577 | 199 ++++++++++++++++++++++++++++++++ src/db/OPTIONS-000582 | 199 ++++++++++++++++++++++++++++++++ src/main.rs | 42 ++----- 30 files changed, 461 insertions(+), 39 deletions(-) create mode 100644 record_link.surql create mode 100644 src/db/000583.sst create mode 100644 src/db/CURRENT create mode 100644 src/db/IDENTITY create mode 100644 src/db/LOCK create mode 100644 src/db/LOG create mode 100644 src/db/LOG.old.1711536591639406 create mode 100644 src/db/LOG.old.1711536727664902 create mode 100644 src/db/LOG.old.1711536785550446 create mode 100644 src/db/LOG.old.1711536866344950 create mode 100644 src/db/LOG.old.1711537050745744 create mode 100644 src/db/LOG.old.1711538120616679 create mode 100644 src/db/LOG.old.1711538196379150 create mode 100644 src/db/LOG.old.1711538303743359 create mode 100644 src/db/LOG.old.1711538366428099 create mode 100644 src/db/LOG.old.1711538422375930 create mode 100644 src/db/LOG.old.1711539011481882 create mode 100644 src/db/LOG.old.1711539135557810 create mode 100644 src/db/LOG.old.1711539259147523 create mode 100644 src/db/LOG.old.1711539272965806 create mode 100644 src/db/LOG.old.1711539323947710 create mode 100644 src/db/LOG.old.1711542150900978 create mode 100644 src/db/LOG.old.1711542273690477 create mode 100644 src/db/LOG.old.1711542323652174 create mode 100644 src/db/LOG.old.1711542330246917 create mode 100644 src/db/MANIFEST-000580 create mode 100644 src/db/OPTIONS-000577 create mode 100644 src/db/OPTIONS-000582 diff --git a/record_link.surql b/record_link.surql new file mode 100644 index 0000000..d9f6e85 --- /dev/null +++ b/record_link.surql @@ -0,0 +1,30 @@ +REMOVE TABLE review; +REMOVE TABLE artist; + +CREATE review; +CREATE artist; + +UPDATE review:00a0ic854u4j7z02s00v +CONTENT { artist: artist:00b2pg847d7b8r08t08t, + id: review:00a0ic854u4j7z02s00v, + person: person:67s8cp304i4p6p83q02d, + product: product:41v2qv923h3o7s55e96l, + rating: 3, review_text: 'repeat exchange meter lawyer academy sunset gang' }; + + + +UPDATE artist:00b2pg847d7b8r08t08t +CONTENT { address: { address_line_1: '816 Cravenny', + address_line_2: NONE, + city: 'Malvern', + coordinates: [9.854998, -0.731803], + country: 'England', post_code: 'HO1D 8WY' }, + company_name: NONE, email: 'acute2086@protonmail.com', + first_name: 'Lasonya', id: artist:00b2pg847d7b8r08t08t, + last_name: 'Spears', name: 'Lasonya Spears', phone: '0800 085411' }; + + +SELECT id,rating, artist.address.city +AS city, artist.email +AS email +FROM review; \ No newline at end of file diff --git a/src/controller.rs b/src/controller.rs index 3953a04..f63c40f 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -1,6 +1,7 @@ +use surrealdb::Response; use surrealdb::{engine::local::Db, Surreal}; use crate::Colorize; -use crate::{Magazine, Record}; +use crate::{Magazine, Record,Feature}; pub async fn add_to(db: &Surreal, data: Vec) -> surrealdb::Result<()> { for magazine in data { @@ -70,22 +71,31 @@ pub async fn list_year(db: &Surreal, year: u32) -> surrealdb::Result<()> { Ok(()) } -pub async fn add_relate(db: &Surreal, topic: String) -> surrealdb::Result<()> { +pub async fn add_relate(db: &Surreal, topic:&str ) -> surrealdb::Result<()> { let _relate = db - .query("RELATE product->featured->($topic)") - .bind(("topic", topic)) + .query("CREATE type::table($table); + let $mag = product:mwevltg3qxgdyng36xep; + let $tp = type::thing('topic', $top); + RELATE $mag->featured->$tp SET time.written = time::now();") + .bind(("top", topic)) + .bind(("table", "topic")) .await?; Ok(()) } pub async fn list_related(db: &Surreal) -> surrealdb::Result<()> { let mut entries = db - .query("SELECT * FROM type::table($table)") - .bind(("table", "featured")) + .query("SELECT id, time.written as time_written FROM featured") .await?; - let entries: Vec = entries.take(0)?; + let entries: Vec = entries.take(0)?; for entry in entries { - println!("{:?} ", entry); - } + println!("added {:?}", entry.time_written.unwrap_or_default()); + } + Ok(()) +} + +pub async fn get_info(db:&Surreal)->surrealdb::Result<()>{ + let mut info = db.query("INFO FOR DB").await?; + //println!("{:?}", info); Ok(()) } diff --git a/src/db/000583.sst b/src/db/000583.sst new file mode 100644 index 0000000000000000000000000000000000000000..239e3e98cb075a9d41232dab3d84102b5498860c GIT binary patch literal 4338 zcmb_fOKc>?8Lk?SJu_xJ_F}Jz9Sk;FM6zajd%An3Jy;vXM7%aucqu3Xg`v8ux~J`a zjH|0Xj}YJz2^4`~IS_;d2#EuVqO2lCD@8)uOB4<~E?jbm7Uh-$HzW|S3RT@RZCma* z7VELxs{ZSLe1H94{Z$Qam(Q)V4FKRv&tARo>A925|XV7f!w289krUb`x ztrpC|oP%K*rcfcA%QDP4KGzyy41e=L)qPq?47o{ z*4ajZ9~`UtS%xQ#^ea*Qzg{$_Zn_UV^FO&NI?dju05FSkX-e86fTMi@V8Xm~^5(li z7F9%m6N&(y1m}`oFnp$aG0rcm{3jTl=a*Hs6O2$<_{pdgD^AZtwzIF(!SPtI*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T @@ -0,0 +1 @@ +MANIFEST-000580 diff --git a/src/db/IDENTITY b/src/db/IDENTITY new file mode 100644 index 0000000..3c23af1 --- /dev/null +++ b/src/db/IDENTITY @@ -0,0 +1 @@ +d60664f5-bda4-42d1-8151-773b111456ea \ No newline at end of file diff --git a/src/db/LOCK b/src/db/LOCK new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG b/src/db/LOG new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711536591639406 b/src/db/LOG.old.1711536591639406 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711536727664902 b/src/db/LOG.old.1711536727664902 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711536785550446 b/src/db/LOG.old.1711536785550446 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711536866344950 b/src/db/LOG.old.1711536866344950 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711537050745744 b/src/db/LOG.old.1711537050745744 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711538120616679 b/src/db/LOG.old.1711538120616679 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711538196379150 b/src/db/LOG.old.1711538196379150 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711538303743359 b/src/db/LOG.old.1711538303743359 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711538366428099 b/src/db/LOG.old.1711538366428099 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711538422375930 b/src/db/LOG.old.1711538422375930 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711539011481882 b/src/db/LOG.old.1711539011481882 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711539135557810 b/src/db/LOG.old.1711539135557810 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711539259147523 b/src/db/LOG.old.1711539259147523 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711539272965806 b/src/db/LOG.old.1711539272965806 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711539323947710 b/src/db/LOG.old.1711539323947710 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711542150900978 b/src/db/LOG.old.1711542150900978 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711542273690477 b/src/db/LOG.old.1711542273690477 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711542323652174 b/src/db/LOG.old.1711542323652174 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/LOG.old.1711542330246917 b/src/db/LOG.old.1711542330246917 new file mode 100644 index 0000000..e69de29 diff --git a/src/db/MANIFEST-000580 b/src/db/MANIFEST-000580 new file mode 100644 index 0000000000000000000000000000000000000000..95354d23fc3886dcd0d0635b9c46cd78323978e0 GIT binary patch literal 1207 zcmb>MooLL;z}Vryw2LL|=Z+sT42+CYIjLo-IVnkcPL(C8<(b8)&iT0oiA9Me`9(c< zPcZFeVgxGY+Qq`M(Jq}~FH4u0s=i`I5(5KcU;UjGGWy2-b|on{odXtLU3sc(0sCwQ zS$PH!@YB~SNi8m6fRXtHnaK=wKncd;)V#bzW3ZyM)Wnj~qSO=+hcPL!B&o#MIK84I zC8w&Qu-GIyv4nxq0Ak#1yN!0NteY21*ucid$iU0U!p^|K9-5b(mtUU8%wfd@HjaTu zpnt7{yRVkZX058&YfZA}GZ@nucCf4!LAZHitD(M}^h$;wa$uj59=cT}#U^G(W!a_a zg&D>c1=)%DdHD>CtPq!evuy*qv~4~tbeT|GDp6i!`{sSyvh9L-58`$vTwqLR+`w|1 zfJ+%6F+xTwTI$#&^2J^KY;mq*Q7FUTk&Q~iL0fsvDe`3NWpyEHehJj=kyw4Vhcau}GX53%$k zdFEdG1^qv#lg=#2a(ut<^@-}`lFwc+m_WiQ4K-006y>LsCYLa1=O(6SrZ8v$-N@ot zT9RK}kY7{+axgQ9XaErm46;Cs%m=ZN`0VEy85r#$)@-sn42+Il@PxyP;zdpS!~3@0 zSVGvHx +} + #[tokio::main] async fn main() -> surrealdb::Result<()> { // handle user input @@ -74,6 +80,8 @@ async fn main() -> surrealdb::Result<()> { // clear old, test data //let _cleanup = db.query("REMOVE TABLE product").await?; + //let _cleanup = db.query("REMOVE TABLE topic").await?; + //let _cleanup = db.query("REMOVE TABLE featured").await?; let _response = db //-- Create an index on the name, month and year fields of the product table @@ -81,34 +89,6 @@ async fn main() -> surrealdb::Result<()> { .await?; let mut data = vec![ - // Magazine { - // name: "Autosport".to_string(), - // price: 1.80, - // day: 12, - // month: 12, - // year: 1987, - // }, - // Magazine { - // name: "Autosport".to_string(), - // price: 2.10, - // day: 1, - // month: 9, - // year: 1985, - // }, - // Magazine { - // name: "Autosport".to_string(), - // price: 0.90, - // day: 22, - // month: 1, - // year: 1984, - // }, - // Magazine { - // name: "Autosport".to_string(), - // price: 1.20, - // day: 23, - // month: 9, - // year: 1984, - // }, ]; data.push(new_mag); @@ -128,8 +108,10 @@ async fn main() -> surrealdb::Result<()> { list_year(&db, 1987).await?; println!("----------------------------------------------------------------"); - //add_relate(&db,"Senna".to_string()); - list_related(&db); + add_relate(&db,"senna3").await?; + list_related(&db).await?; + //get_info(&db).await?; + //println!("Done"); Ok(()) }