You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@age.apache.org by GitBox <gi...@apache.org> on 2021/12/21 04:28:30 UTC

[GitHub] [incubator-age] emotionbug edited a comment on issue #162: Rust-Postgres, binary support - ANTLR, Can you explain the parsing workflow?

emotionbug edited a comment on issue #162:
URL: https://github.com/apache/incubator-age/issues/162#issuecomment-998462127


   I tested again. it works.
   
   ```sh
   git clone -b binary_io --single-branch https://github.com/emotionbug/incubator-age.git
   make -j16 && make install -j16
   ```
   
   ```psql
   update pg_type set typsend = 'ag_catalog.agtype_send', typreceive = 'ag_catalog.agtype_recv' where typname = 'agtype';
   ```
   
   ```rust
   use postgres::{Client, Error, NoTls};
   use postgres::types::{FromSql, Type};
   
   struct AgType<'a>(&'a str);
   
   
   impl<'a> FromSql<'a> for AgType<'a> {
       fn from_sql(_: &Type, raw: &'a [u8]) -> Result<AgType<'a>, Box<dyn std::error::Error + Sync + Send>> {
           let t = postgres_protocol::types::text_from_sql(raw)?;
           Ok(AgType(t))
       }
   
       fn accepts(ty: &Type) -> bool {
           ty.name() == "agtype"
       }
   }
   
   pub fn graph_list() -> Result<(), Error> {
       let conn_string = "host=172.17.0.2 port=5432 dbname=postgres user=postgres password=postgres";
       let mut client = Client::connect(conn_string, NoTls)?;
   
   
       &client.batch_execute("LOAD \'age\'")?;
       &client.batch_execute("SET search_path = ag_catalog, \"$user\", public")?;
       // &client.batch_execute("SELECT * from create_graph('text_test')")?;
       // &client.batch_execute("SELECT * from cypher('text_test', $$ CREATE (V:node{id:1}) $$) as (V agtype)")?;
   
       for types in &client.query("SELECT count(*) FROM ag_graph WHERE name= 'text_test'", &[])? {
           println!("{:?}", types)
       }
   
   
       for row in client.query("SELECT * from cypher('text_test', $$ MATCH (V:node) RETURN V $$) as (V agtype)", &[])? {
           let path: AgType = row.get(0);
           println!("{:?}", path.0);
       }
       Ok(())
   }
   
   fn main() {
       match graph_list() {
           Ok(r) => { println!("Succeeded! {:?} ", r); }
           Err(e) => { println!("Error: {}!", e); }
       }
   }
   
   ```
   
   if you are not working, check `pg_type` record.
   ```
   postgres=# select typreceive, typsend from pg_type where typname = 'agtype';
          typreceive       |        typsend         
   ------------------------+------------------------
    ag_catalog.agtype_recv | ag_catalog.agtype_send
   (1 row)
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org