|
467 | 467 | //! ```
|
468 | 468 | //! ## Date
|
469 | 469 | //!
|
| 470 | +//! See [NaiveDate][naive_date] for date abstraction, it captures the date without time component. |
| 471 | +//! |
| 472 | +//! [naive_date]: https://docs.rs/chrono/0.4.19/chrono/naive/struct.NaiveDate.html |
| 473 | +//! |
470 | 474 | //! ```
|
471 | 475 | //! use neo4rs::*;
|
472 | 476 | //! use futures::stream::*;
|
|
493 | 497 | //!
|
494 | 498 | //! ## Time
|
495 | 499 | //!
|
496 |
| -//! Neo4rs uses [chrono][chrono] crate for time abstractions. |
| 500 | +//! * [NaiveTime][naive_time] captures only the time of the day |
| 501 | +//! * `tuple`([NaiveTime][naive_time], `Option`<[FixedOffset][fixed_offset]>) captures the time of the day along with the |
| 502 | +//! offset |
497 | 503 | //!
|
498 |
| -//! [chrono]: https://crates.io/crates/chrono |
| 504 | +//! [naive_time]: https://docs.rs/chrono/0.4.19/chrono/naive/struct.NaiveTime.html |
| 505 | +//! [fixed_offset]: https://docs.rs/chrono/0.4.19/chrono/offset/struct.FixedOffset.html |
499 | 506 | //!
|
500 | 507 | //!
|
501 | 508 | //! ### Time as param
|
502 | 509 | //!
|
503 |
| -//! Pass a time (without offset) as a parameter to the query: |
| 510 | +//! Pass a time as a parameter to the query: |
504 | 511 | //!
|
505 | 512 | //! ```
|
506 | 513 | //! use neo4rs::*;
|
|
583 | 590 | //!
|
584 | 591 | //! ```
|
585 | 592 | //!
|
| 593 | +//! |
| 594 | +//! ## DateTime |
| 595 | +//! |
| 596 | +//! |
| 597 | +//! * [DateTime][date_time] captures the date and time with offset |
| 598 | +//! * [NaiveDateTime][naive_date_time] captures the date time without offset |
| 599 | +//! * `tuple`([NaiveDateTime][naive_date_time], String) captures the date/time and the time zone id |
| 600 | +//! |
| 601 | +//! [date_time]: https://docs.rs/chrono/0.4.19/chrono/struct.DateTime.html |
| 602 | +//! [naive_date_time]: https://docs.rs/chrono/0.4.19/chrono/struct.NaiveDateTime.html |
| 603 | +//! |
| 604 | +//! |
| 605 | +//! ### DateTime as param |
| 606 | +//! |
| 607 | +//! Pass a DateTime as parameter to the query: |
| 608 | +//! |
| 609 | +//! ``` |
| 610 | +//! use neo4rs::*; |
| 611 | +//! use futures::stream::*; |
| 612 | +//! use uuid::Uuid; |
| 613 | +//! |
| 614 | +//! #[tokio::main] |
| 615 | +//! async fn main() { |
| 616 | +//! let uri = "127.0.0.1:7687"; |
| 617 | +//! let user = "neo4j"; |
| 618 | +//! let pass = "neo"; |
| 619 | +//! let graph = Graph::new(uri, user, pass).await.unwrap(); |
| 620 | +//! |
| 621 | +//! //send datetime as parameter in the query |
| 622 | +//! let datetime = chrono::DateTime::parse_from_rfc2822("Tue, 01 Jul 2003 10:52:37 +0200").unwrap(); |
| 623 | +//! |
| 624 | +//! let mut result = graph |
| 625 | +//! .execute(query("RETURN $d as output").param("d", datetime)) |
| 626 | +//! .await |
| 627 | +//! .unwrap(); |
| 628 | +//! let row = result.next().await.unwrap().unwrap(); |
| 629 | +//! let t: chrono::DateTime<chrono::FixedOffset> = row.get("output").unwrap(); |
| 630 | +//! assert_eq!(t.to_string(), "2003-07-01 10:52:37 +02:00"); |
| 631 | +//! assert!(result.next().await.unwrap().is_none()); |
| 632 | +//! |
| 633 | +//! //send NaiveDateTime as parameter in the query |
| 634 | +//! let localdatetime = chrono::NaiveDateTime::parse_from_str("2015-07-01 08:55:59.123", "%Y-%m-%d %H:%M:%S%.f").unwrap(); |
| 635 | +//! |
| 636 | +//! let mut result = graph |
| 637 | +//! .execute(query("RETURN $d as output").param("d", localdatetime)) |
| 638 | +//! .await |
| 639 | +//! .unwrap(); |
| 640 | +//! let row = result.next().await.unwrap().unwrap(); |
| 641 | +//! let t: chrono::NaiveDateTime = row.get("output").unwrap(); |
| 642 | +//! assert_eq!(t.to_string(), "2015-07-01 08:55:59.123"); |
| 643 | +//! assert!(result.next().await.unwrap().is_none()); |
| 644 | +//! |
| 645 | +//! //send NaiveDateTime with timezone id as parameter in the query |
| 646 | +//! let datetime = chrono::NaiveDateTime::parse_from_str("2015-07-03 08:55:59.555", "%Y-%m-%d %H:%M:%S%.f").unwrap(); |
| 647 | +//! let timezone = "Europe/Paris"; |
| 648 | +//! |
| 649 | +//! let mut result = graph |
| 650 | +//! .execute(query("RETURN $d as output").param("d", (datetime, timezone))) |
| 651 | +//! .await |
| 652 | +//! .unwrap(); |
| 653 | +//! let row = result.next().await.unwrap().unwrap(); |
| 654 | +//! let (time, zone): (chrono::NaiveDateTime, String) = row.get("output").unwrap(); |
| 655 | +//! assert_eq!(time.to_string(), "2015-07-03 08:55:59.555"); |
| 656 | +//! assert_eq!(zone, "Europe/Paris"); |
| 657 | +//! assert!(result.next().await.unwrap().is_none()); |
| 658 | +//! |
| 659 | +//! } |
| 660 | +//! ``` |
| 661 | +//! |
| 662 | +//! ### Parsing DateTime from result |
| 663 | +//! |
| 664 | +//! ``` |
| 665 | +//! use neo4rs::*; |
| 666 | +//! use futures::stream::*; |
| 667 | +//! use uuid::Uuid; |
| 668 | +//! |
| 669 | +//! #[tokio::main] |
| 670 | +//! async fn main() { |
| 671 | +//! let uri = "127.0.0.1:7687"; |
| 672 | +//! let user = "neo4j"; |
| 673 | +//! let pass = "neo"; |
| 674 | +//! let graph = Graph::new(uri, user, pass).await.unwrap(); |
| 675 | +//! |
| 676 | +//! //Parse NaiveDateTime from result |
| 677 | +//! let mut result = graph |
| 678 | +//! .execute(query( |
| 679 | +//! "WITH localdatetime('2015-06-24T12:50:35.556') AS t RETURN t", |
| 680 | +//! )) |
| 681 | +//! .await |
| 682 | +//! .unwrap(); |
| 683 | +//! let row = result.next().await.unwrap().unwrap(); |
| 684 | +//! let t: chrono::NaiveDateTime = row.get("t").unwrap(); |
| 685 | +//! assert_eq!(t.to_string(), "2015-06-24 12:50:35.556"); |
| 686 | +//! assert!(result.next().await.unwrap().is_none()); |
| 687 | +//! |
| 688 | +//! //Parse DateTime from result |
| 689 | +//! let mut result = graph |
| 690 | +//! .execute(query( |
| 691 | +//! "WITH datetime('2015-06-24T12:50:35.777+0100') AS t RETURN t", |
| 692 | +//! )) |
| 693 | +//! .await |
| 694 | +//! .unwrap(); |
| 695 | +//! let row = result.next().await.unwrap().unwrap(); |
| 696 | +//! let t: chrono::DateTime<chrono::FixedOffset> = row.get("t").unwrap(); |
| 697 | +//! assert_eq!(t.to_string(), "2015-06-24 12:50:35.777 +01:00"); |
| 698 | +//! assert!(result.next().await.unwrap().is_none()); |
| 699 | +//! |
| 700 | +//! |
| 701 | +//! //Parse NaiveDateTime with zone id from result |
| 702 | +//! let mut result = graph |
| 703 | +//! .execute(query( |
| 704 | +//! "WITH datetime({ year:1984, month:11, day:11, hour:12, minute:31, second:14, nanosecond: 645876123, timezone:'Europe/Stockholm' }) AS d return d", |
| 705 | +//! )) |
| 706 | +//! .await |
| 707 | +//! .unwrap(); |
| 708 | +//! let row = result.next().await.unwrap().unwrap(); |
| 709 | +//! let (datetime, zone_id): (chrono::NaiveDateTime, String) = row.get("d").unwrap(); |
| 710 | +//! assert_eq!(datetime.to_string(), "1984-11-11 12:31:14.645876123"); |
| 711 | +//! assert_eq!(zone_id, "Europe/Stockholm"); |
| 712 | +//! assert!(result.next().await.unwrap().is_none()); |
| 713 | +//! |
| 714 | +//! } |
| 715 | +//! |
| 716 | +//! ``` |
| 717 | +//! |
| 718 | +//! |
| 719 | +//! |
586 | 720 | //! ## Path
|
587 | 721 | //!
|
588 | 722 | //! ```
|
|
0 commit comments