diff --git a/README.md b/README.md index e2e5d0cc..a81602b0 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ rdb.alter( * [Branch naming rule](#branch-naming-rule) - + --- diff --git a/allographer.nimble b/allographer.nimble index f12d167a..ad8da63d 100644 --- a/allographer.nimble +++ b/allographer.nimble @@ -54,4 +54,5 @@ proc generateToc(dir: string) = task toc, "Generate TOC": generateToc(".") - generateToc("./documents") + generateToc("./documents/rdb") + generateToc("./documents/surrealdb") diff --git a/docs/connection.html b/docs/connection.html index f9570685..e4cdcc2c 100644 --- a/docs/connection.html +++ b/docs/connection.html @@ -187,7 +187,7 @@

Exports

diff --git a/docs/env.html b/docs/env.html index 4a1ffcc4..a3d39ed2 100644 --- a/docs/env.html +++ b/docs/env.html @@ -176,7 +176,7 @@

Consts

diff --git a/docs/query_builder.html b/docs/query_builder.html index 0b1dc606..ba6a7cda 100644 --- a/docs/query_builder.html +++ b/docs/query_builder.html @@ -137,7 +137,7 @@

Exports

diff --git a/docs/query_builder/enums.html b/docs/query_builder/enums.html index 1326dbf7..77f2a15a 100644 --- a/docs/query_builder/enums.html +++ b/docs/query_builder/enums.html @@ -150,7 +150,7 @@

Types

diff --git a/docs/query_builder/error.html b/docs/query_builder/error.html index 6748cbbd..920a0ecb 100644 --- a/docs/query_builder/error.html +++ b/docs/query_builder/error.html @@ -160,7 +160,7 @@

Procs

diff --git a/docs/query_builder/log.html b/docs/query_builder/log.html index b0527465..3b8c16a7 100644 --- a/docs/query_builder/log.html +++ b/docs/query_builder/log.html @@ -197,7 +197,7 @@

Procs

diff --git a/docs/query_builder/rdb/databases/database_types.html b/docs/query_builder/rdb/databases/database_types.html index 85fe99b5..a2920a56 100644 --- a/docs/query_builder/rdb/databases/database_types.html +++ b/docs/query_builder/rdb/databases/database_types.html @@ -471,7 +471,7 @@

Procs

diff --git a/docs/query_builder/rdb/databases/mariadb/mariadb_impl.html b/docs/query_builder/rdb/databases/mariadb/mariadb_impl.html index 7c78425d..a5daecb4 100644 --- a/docs/query_builder/rdb/databases/mariadb/mariadb_impl.html +++ b/docs/query_builder/rdb/databases/mariadb/mariadb_impl.html @@ -204,7 +204,7 @@

Procs

diff --git a/docs/query_builder/rdb/databases/mariadb/mariadb_lib.html b/docs/query_builder/rdb/databases/mariadb/mariadb_lib.html index 09fbf0c4..d70fa0f9 100644 --- a/docs/query_builder/rdb/databases/mariadb/mariadb_lib.html +++ b/docs/query_builder/rdb/databases/mariadb/mariadb_lib.html @@ -323,7 +323,7 @@

Iterators

diff --git a/docs/query_builder/rdb/databases/mariadb/mariadb_rdb.html b/docs/query_builder/rdb/databases/mariadb/mariadb_rdb.html index fff4edbb..ab5364c7 100644 --- a/docs/query_builder/rdb/databases/mariadb/mariadb_rdb.html +++ b/docs/query_builder/rdb/databases/mariadb/mariadb_rdb.html @@ -5746,7 +5746,7 @@

Procs

diff --git a/docs/query_builder/rdb/databases/mysql/mysql_impl.html b/docs/query_builder/rdb/databases/mysql/mysql_impl.html index 4eff4525..6aaf5620 100644 --- a/docs/query_builder/rdb/databases/mysql/mysql_impl.html +++ b/docs/query_builder/rdb/databases/mysql/mysql_impl.html @@ -204,7 +204,7 @@

Procs

diff --git a/docs/query_builder/rdb/databases/mysql/mysql_lib.html b/docs/query_builder/rdb/databases/mysql/mysql_lib.html index 3720f25f..9cb909d5 100644 --- a/docs/query_builder/rdb/databases/mysql/mysql_lib.html +++ b/docs/query_builder/rdb/databases/mysql/mysql_lib.html @@ -217,7 +217,7 @@

Procs

diff --git a/docs/query_builder/rdb/databases/mysql/mysql_rdb.html b/docs/query_builder/rdb/databases/mysql/mysql_rdb.html index 50f9cef9..6bce4fdd 100644 --- a/docs/query_builder/rdb/databases/mysql/mysql_rdb.html +++ b/docs/query_builder/rdb/databases/mysql/mysql_rdb.html @@ -5733,7 +5733,7 @@

Procs

diff --git a/docs/query_builder/rdb/databases/postgre/postgre_impl.html b/docs/query_builder/rdb/databases/postgre/postgre_impl.html index 9aec605f..2a46d36f 100644 --- a/docs/query_builder/rdb/databases/postgre/postgre_impl.html +++ b/docs/query_builder/rdb/databases/postgre/postgre_impl.html @@ -251,7 +251,7 @@

Procs

diff --git a/docs/query_builder/rdb/databases/postgre/postgre_lib.html b/docs/query_builder/rdb/databases/postgre/postgre_lib.html index f4ff3e0c..9d2c96c9 100644 --- a/docs/query_builder/rdb/databases/postgre/postgre_lib.html +++ b/docs/query_builder/rdb/databases/postgre/postgre_lib.html @@ -218,7 +218,7 @@

Procs

diff --git a/docs/query_builder/rdb/databases/postgre/postgre_rdb.html b/docs/query_builder/rdb/databases/postgre/postgre_rdb.html index 6fe8b3d2..76892db3 100644 --- a/docs/query_builder/rdb/databases/postgre/postgre_rdb.html +++ b/docs/query_builder/rdb/databases/postgre/postgre_rdb.html @@ -2281,7 +2281,7 @@

Procs

diff --git a/docs/query_builder/rdb/databases/sqlite/sqlite_impl.html b/docs/query_builder/rdb/databases/sqlite/sqlite_impl.html index afa8d5d1..c7409367 100644 --- a/docs/query_builder/rdb/databases/sqlite/sqlite_impl.html +++ b/docs/query_builder/rdb/databases/sqlite/sqlite_impl.html @@ -267,7 +267,7 @@

Procs

diff --git a/docs/query_builder/rdb/databases/sqlite/sqlite_lib.html b/docs/query_builder/rdb/databases/sqlite/sqlite_lib.html index 4096ecf1..459c21a8 100644 --- a/docs/query_builder/rdb/databases/sqlite/sqlite_lib.html +++ b/docs/query_builder/rdb/databases/sqlite/sqlite_lib.html @@ -330,7 +330,7 @@

Templates

diff --git a/docs/query_builder/rdb/databases/sqlite/sqlite_rdb.html b/docs/query_builder/rdb/databases/sqlite/sqlite_rdb.html index f8013884..297845ec 100644 --- a/docs/query_builder/rdb/databases/sqlite/sqlite_rdb.html +++ b/docs/query_builder/rdb/databases/sqlite/sqlite_rdb.html @@ -2608,7 +2608,7 @@

Procs

diff --git a/docs/query_builder/rdb/query/builder.html b/docs/query_builder/rdb/query/builder.html index 36588344..72c56364 100644 --- a/docs/query_builder/rdb/query/builder.html +++ b/docs/query_builder/rdb/query/builder.html @@ -329,7 +329,7 @@

Procs

diff --git a/docs/query_builder/rdb/query/exec.html b/docs/query_builder/rdb/query/exec.html index d13e2182..3404f92f 100644 --- a/docs/query_builder/rdb/query/exec.html +++ b/docs/query_builder/rdb/query/exec.html @@ -329,7 +329,7 @@

Exports

diff --git a/docs/query_builder/rdb/query/generator.html b/docs/query_builder/rdb/query/generator.html index 6f725c3e..a3309533 100644 --- a/docs/query_builder/rdb/query/generator.html +++ b/docs/query_builder/rdb/query/generator.html @@ -564,7 +564,7 @@

Procs

diff --git a/docs/query_builder/rdb/query/grammar.html b/docs/query_builder/rdb/query/grammar.html index 98cb5742..1c5a9ea3 100644 --- a/docs/query_builder/rdb/query/grammar.html +++ b/docs/query_builder/rdb/query/grammar.html @@ -467,7 +467,7 @@

Procs

diff --git a/docs/query_builder/rdb/query/seeder.html b/docs/query_builder/rdb/query/seeder.html index 767e25b6..a6ec90ba 100644 --- a/docs/query_builder/rdb/query/seeder.html +++ b/docs/query_builder/rdb/query/seeder.html @@ -160,7 +160,7 @@

Templates

diff --git a/docs/query_builder/rdb/query/transaction.html b/docs/query_builder/rdb/query/transaction.html index 714018a3..c5d0f52d 100644 --- a/docs/query_builder/rdb/query/transaction.html +++ b/docs/query_builder/rdb/query/transaction.html @@ -150,7 +150,7 @@

Templates

diff --git a/docs/query_builder/rdb/rdb_interface.html b/docs/query_builder/rdb/rdb_interface.html index 1906fcbf..abcd2c15 100644 --- a/docs/query_builder/rdb/rdb_interface.html +++ b/docs/query_builder/rdb/rdb_interface.html @@ -739,7 +739,7 @@

Procs

diff --git a/docs/query_builder/rdb/rdb_types.html b/docs/query_builder/rdb/rdb_types.html index 7dfe758e..564131d1 100644 --- a/docs/query_builder/rdb/rdb_types.html +++ b/docs/query_builder/rdb/rdb_types.html @@ -203,7 +203,7 @@

Types

diff --git a/docs/query_builder/rdb/rdb_utils.html b/docs/query_builder/rdb/rdb_utils.html index f541f963..b87c0f64 100644 --- a/docs/query_builder/rdb/rdb_utils.html +++ b/docs/query_builder/rdb/rdb_utils.html @@ -242,7 +242,7 @@

Procs

diff --git a/docs/query_builder/surreal/databases/surreal_impl.html b/docs/query_builder/surreal/databases/surreal_impl.html index 3d588924..546e14d8 100644 --- a/docs/query_builder/surreal/databases/surreal_impl.html +++ b/docs/query_builder/surreal/databases/surreal_impl.html @@ -228,7 +228,7 @@

Procs

diff --git a/docs/query_builder/surreal/databases/surreal_lib.html b/docs/query_builder/surreal/databases/surreal_lib.html index ca3dfe42..163cbd95 100644 --- a/docs/query_builder/surreal/databases/surreal_lib.html +++ b/docs/query_builder/surreal/databases/surreal_lib.html @@ -153,7 +153,7 @@

Procs

diff --git a/docs/query_builder/surreal/databases/surreal_rdb.html b/docs/query_builder/surreal/databases/surreal_rdb.html index bb7d0c10..039c452d 100644 --- a/docs/query_builder/surreal/databases/surreal_rdb.html +++ b/docs/query_builder/surreal/databases/surreal_rdb.html @@ -162,7 +162,7 @@

Types

diff --git a/docs/query_builder/surreal/query/builder.html b/docs/query_builder/surreal/query/builder.html index 6df69273..caae567f 100644 --- a/docs/query_builder/surreal/query/builder.html +++ b/docs/query_builder/surreal/query/builder.html @@ -277,7 +277,7 @@

Procs

diff --git a/docs/query_builder/surreal/query/exec.html b/docs/query_builder/surreal/query/exec.html index b61d7ac4..f3830507 100644 --- a/docs/query_builder/surreal/query/exec.html +++ b/docs/query_builder/surreal/query/exec.html @@ -191,7 +191,7 @@

Procs

diff --git a/docs/query_builder/surreal/query/generator.html b/docs/query_builder/surreal/query/generator.html index 4d25146a..e492482a 100644 --- a/docs/query_builder/surreal/query/generator.html +++ b/docs/query_builder/surreal/query/generator.html @@ -442,7 +442,7 @@

Procs

diff --git a/docs/query_builder/surreal/query/grammar.html b/docs/query_builder/surreal/query/grammar.html index e5d0a49c..eaf280f6 100644 --- a/docs/query_builder/surreal/query/grammar.html +++ b/docs/query_builder/surreal/query/grammar.html @@ -324,7 +324,7 @@

Procs

diff --git a/docs/query_builder/surreal/surreal_interface.html b/docs/query_builder/surreal/surreal_interface.html index 80375f69..82d2dabd 100644 --- a/docs/query_builder/surreal/surreal_interface.html +++ b/docs/query_builder/surreal/surreal_interface.html @@ -391,7 +391,7 @@

Procs

diff --git a/docs/query_builder/surreal/surreal_types.html b/docs/query_builder/surreal/surreal_types.html index 31c36e4a..6029abe5 100644 --- a/docs/query_builder/surreal/surreal_types.html +++ b/docs/query_builder/surreal/surreal_types.html @@ -128,7 +128,7 @@

src/allographer/query_builder/surreal/surreal_types

  • SurrealId
  • + id: string">SurrealId @@ -232,7 +232,7 @@

    Types

    SurrealId = object
       table*: string
    -  id*: string
    +  id: string
     
    @@ -340,7 +340,7 @@

    Procs

    diff --git a/docs/query_builder/surreal/surreal_utils.html b/docs/query_builder/surreal/surreal_utils.html index 7eb27e44..3dd608aa 100644 --- a/docs/query_builder/surreal/surreal_utils.html +++ b/docs/query_builder/surreal/surreal_utils.html @@ -152,7 +152,7 @@

    Procs

    diff --git a/docs/schema_builder.html b/docs/schema_builder.html index 6179071d..ebc43034 100644 --- a/docs/schema_builder.html +++ b/docs/schema_builder.html @@ -137,7 +137,7 @@

    Exports

    diff --git a/docs/schema_builder/grammars.html b/docs/schema_builder/grammars.html index 1b8e3ee4..8287d305 100644 --- a/docs/schema_builder/grammars.html +++ b/docs/schema_builder/grammars.html @@ -876,7 +876,7 @@

    Procs

    diff --git a/docs/schema_builder/queries/generator_utils.html b/docs/schema_builder/queries/generator_utils.html index e27a8f88..b5b7533f 100644 --- a/docs/schema_builder/queries/generator_utils.html +++ b/docs/schema_builder/queries/generator_utils.html @@ -140,7 +140,7 @@

    Procs

    diff --git a/docs/schema_builder/queries/mysql/impl.html b/docs/schema_builder/queries/mysql/impl.html index 6e2dcbb5..ea50f086 100644 --- a/docs/schema_builder/queries/mysql/impl.html +++ b/docs/schema_builder/queries/mysql/impl.html @@ -507,7 +507,7 @@

    Procs

    diff --git a/docs/schema_builder/queries/mysql/mysql_query.html b/docs/schema_builder/queries/mysql/mysql_query.html index 12bf77f2..a1c31ad2 100644 --- a/docs/schema_builder/queries/mysql/mysql_query.html +++ b/docs/schema_builder/queries/mysql/mysql_query.html @@ -187,7 +187,7 @@

    Procs

    diff --git a/docs/schema_builder/queries/postgre/impl.html b/docs/schema_builder/queries/postgre/impl.html index d539504b..bbabdfd8 100644 --- a/docs/schema_builder/queries/postgre/impl.html +++ b/docs/schema_builder/queries/postgre/impl.html @@ -529,7 +529,7 @@

    Procs

    diff --git a/docs/schema_builder/queries/postgre/postgre_query.html b/docs/schema_builder/queries/postgre/postgre_query.html index 649a0cff..b9b31b65 100644 --- a/docs/schema_builder/queries/postgre/postgre_query.html +++ b/docs/schema_builder/queries/postgre/postgre_query.html @@ -201,7 +201,7 @@

    Procs

    diff --git a/docs/schema_builder/queries/query_interface.html b/docs/schema_builder/queries/query_interface.html index 8cda492d..6e28f0c1 100644 --- a/docs/schema_builder/queries/query_interface.html +++ b/docs/schema_builder/queries/query_interface.html @@ -179,7 +179,7 @@

    Types

    diff --git a/docs/schema_builder/queries/sqlite/impl.html b/docs/schema_builder/queries/sqlite/impl.html index 3da9406a..a5769bcb 100644 --- a/docs/schema_builder/queries/sqlite/impl.html +++ b/docs/schema_builder/queries/sqlite/impl.html @@ -438,7 +438,7 @@

    Procs

    diff --git a/docs/schema_builder/queries/sqlite/sqlite_query.html b/docs/schema_builder/queries/sqlite/sqlite_query.html index 47d48631..bbd244db 100644 --- a/docs/schema_builder/queries/sqlite/sqlite_query.html +++ b/docs/schema_builder/queries/sqlite/sqlite_query.html @@ -201,7 +201,7 @@

    Procs

    diff --git a/docs/schema_builder/schema.html b/docs/schema_builder/schema.html index eb743af5..f361f38a 100644 --- a/docs/schema_builder/schema.html +++ b/docs/schema_builder/schema.html @@ -165,7 +165,7 @@

    Procs

    diff --git a/docs/theindex.html b/docs/theindex.html index 0be0ff23..170c832d 100644 --- a/docs/theindex.html +++ b/docs/theindex.html @@ -6854,7 +6854,7 @@

    Index

    diff --git a/documents/rdb/benchmark_result.md b/documents/rdb/benchmark_result.md index 0496243d..eb26e04b 100644 --- a/documents/rdb/benchmark_result.md +++ b/documents/rdb/benchmark_result.md @@ -1,3 +1,13 @@ +## index + + * [index](#index) + * [0.23.4](#0234) + + + + + + ## 0.23.4 ```sh cd example @@ -22,4 +32,4 @@ update |3|0.1847369050000012| |4|0.2267158040000012| |5|0.2636497700000007| -|Avg|0.2571823782000007| \ No newline at end of file +|Avg|0.2571823782000007| diff --git a/documents/rdb/query_builder.md b/documents/rdb/query_builder.md index 171fc826..669a31ed 100644 --- a/documents/rdb/query_builder.md +++ b/documents/rdb/query_builder.md @@ -4,37 +4,39 @@ Example: Query Builder for RDB ## index - * [Example: Query Builder](#example-query-builder) - * [index](#index) - * [SELECT](#select) - * [return JsonNode](#return-jsonnode) - * [return Object](#return-object) - * [get](#get) - * [first](#first) - * [find](#find) - * [join](#join) - * [where](#where) - * [orWhere](#orwhere) - * [whereBetween](#wherebetween) - * [whereNotBetween](#wherenotbetween) - * [whereIn](#wherein) - * [whereNotIn](#wherenotin) - * [whereNull](#wherenull) - * [groupBy_having](#groupby_having) - * [orderBy](#orderby) - * [limit_offset](#limit_offset) - * [paginate](#paginate) - * [fastPaginate](#fastpaginate) - * [INSERT](#insert) - * [Return ID Insert](#return-id-insert) - * [UPDATE](#update) - * [DELETE](#delete) - * [Plain Response](#plain-response) - * [Raw_SQL](#raw_sql) - * [Aggregates](#aggregates) - * [Transaction](#transaction) - - +* [Example: Query Builder for RDB](#example-query-builder-for-rdb) + * [index](#index) + * [Create Connection](#create-connection) + * [SELECT](#select) + * [return JsonNode](#return-jsonnode) + * [return Object](#return-object) + * [get](#get) + * [first](#first) + * [find](#find) + * [join](#join) + * [where](#where) + * [orWhere](#orwhere) + * [whereBetween](#wherebetween) + * [whereNotBetween](#wherenotbetween) + * [whereIn](#wherein) + * [whereNotIn](#wherenotin) + * [whereNull](#wherenull) + * [groupBy_having](#groupby_having) + * [orderBy](#orderby) + * [limit_offset](#limit_offset) + * [paginate](#paginate) + * [fastPaginate](#fastpaginate) + * [INSERT](#insert) + * [Return ID Insert](#return-id-insert) + * [UPDATE](#update) + * [DELETE](#delete) + * [Plain Response](#plain-response) + * [Raw SQL](#raw-sql) + * [Aggregates](#aggregates) + * [Transaction](#transaction) + + + --- @@ -625,7 +627,7 @@ echo rdb.table("users").firstPlain().await >> @["1", "user1", "user1@gmail.com"] ``` -## Raw_SQL +## Raw SQL [to index](#INDEX) ```nim diff --git a/documents/rdb/schema_builder.md b/documents/rdb/schema_builder.md index 8a8f966e..84ed5371 100644 --- a/documents/rdb/schema_builder.md +++ b/documents/rdb/schema_builder.md @@ -4,26 +4,27 @@ Example: Schema Builder ## index - * [Example: Schema Builder](#example-schema-builder) - * [index](#index) - * [Create table](#create-table) - * [Alter Table](#alter-table) - * [add column](#add-column) - * [change column](#change-column) - * [delete column](#delete-column) - * [rename table](#rename-table) - * [drop table](#drop-table) - * [Migration history](#migration-history) - * [seeder template](#seeder-template) - * [integer](#integer) - * [float](#float) - * [char](#char) - * [date](#date) - * [others](#others) - * [options](#options) - * [Foreign Key Constraints](#foreign-key-constraints) - - +* [Example: Schema Builder](#example-schema-builder) + * [index](#index) + * [Create table](#create-table) + * [Alter Table](#alter-table) + * [add column](#add-column) + * [change column](#change-column) + * [delete column](#delete-column) + * [rename table](#rename-table) + * [drop table](#drop-table) + * [Migration history](#migration-history) + * [seeder template](#seeder-template) + * [integer](#integer) + * [float](#float) + * [char](#char) + * [date](#date) + * [others](#others) + * [options](#options) + * [Foreign Key Constraints](#foreign-key-constraints) + + + --- diff --git a/documents/rdb/typeDifinition.md b/documents/rdb/typeDifinition.md index 97c0cf3a..0c606857 100644 --- a/documents/rdb/typeDifinition.md +++ b/documents/rdb/typeDifinition.md @@ -1,12 +1,13 @@ ## index - * [index](#index) - * [JInt](#jint) - * [JFloat](#jfloat) - * [JBool](#jbool) + * [index](#index) + * [JInt](#jint) + * [JFloat](#jfloat) + * [JBool](#jbool) - + + --- diff --git a/documents/surrealdb/query_builder.md b/documents/surrealdb/query_builder.md index d9f9ab79..b5354561 100644 --- a/documents/surrealdb/query_builder.md +++ b/documents/surrealdb/query_builder.md @@ -4,6 +4,33 @@ Example: Query Builder for SurrealDB ## index +* [Example: Query Builder for SurrealDB](#example-query-builder-for-surrealdb) + * [index](#index) + * [About SurrealDB](#about-surrealdb) + * [Create Connection](#create-connection) + * [SELECT](#select) + * [get](#get) + * [first](#first) + * [find](#find) + * [where](#where) + * [fetch](#fetch) + * [INSERT](#insert) + * [insert single row](#insert-single-row) + * [insert rows](#insert-rows) + * [insertId](#insertid) + * [UPDATE](#update) + * [DELETE](#delete) + * [delete all](#delete-all) + * [delete row](#delete-row) + * [Raw Query](#raw-query) + * [Aggregates](#aggregates) + * [count](#count) + * [max](#max) + * [min](#min) + + + + --- @@ -12,10 +39,12 @@ Example: Query Builder for SurrealDB [SurrealDB official docs](https://surrealdb.com/docs) [SurrealDB Github](https://github.com/surrealdb/surrealdb) -SurrealDB is a next-generation database built on Rust that can handle all types of data structures-relational, document, and graph-and can run in-memory, on a single node, or in a distributed environment. +SurrealDB is a next-generation database built on Rust that can handle all type of data structures-relational, document, and graph-and can run in-memory, on a single node, or in a distributed environment. It's response is JSON and allographer return as `JsonNode`. ## Create Connection +[to index](#index) + ```nim import allographer/connection @@ -27,10 +56,12 @@ let surreal = dbOpen(SurrealDb, "test", "test", "user", "pass", "http://surreal" ## SELECT [to index](#index) +https://surrealdb.com/docs/surrealql/statements/select + When it returns following table ```sql -INSERT INTO `types` [ +INSERT INTO `type` [ {"bool":true,"string":"alice","int":1,"float":3.14,"datetime":"2023-06-05T11:58:42+00:00"}, {"bool":false,"string":"bob","int":2,"float":1.11,"datetime":"2023-06-06T11:58:42+00:00"} ] @@ -52,14 +83,14 @@ echo surreal.table("user").get() ``` ```nim -DEBUG SELECT * FROM `types` [] +DEBUG SELECT * FROM `type` [] @[ { "bool":true, "datetime":"2023-06-05T12:05:07Z", "float":3.14, - "id":"types:9nxye3dons0juyelv5if", + "id":"type:9nxye3dons0juyelv5if", "int":1, "string":"alice" }, @@ -67,7 +98,7 @@ DEBUG SELECT * FROM `types` [] "bool":false, "datetime":"2023-06-06T12:05:07Z" ,"float":1.11, - "id":"types:tw9iqdycdz9h1egtjkwb", + "id":"type:tw9iqdycdz9h1egtjkwb", "int":2, "string":"bob" } @@ -78,44 +109,44 @@ DEBUG SELECT * FROM `types` [] Retrieving a single row from a table. This returns `Option[JsonNode]` ```nim -let res = surreal.table("types").first().await +let res = surreal.table("type").first().await if res.isSome(): echo firstRes.get() ``` ```nim -DEBUG SELECT * FROM `types` LIMIT 1 [] +DEBUG SELECT * FROM `type` LIMIT 1 [] { "bool":true, "datetime":"2023-06-05T12:08:47Z", "float":3.14, - "id":"types:64t0w6gpnye7tdf083ch", + "id":"type:64t0w6gpnye7tdf083ch", "int":1, "string":"alice" } ``` ### find -Retrieve a single row by id. This returns `Option[JsonNode]` -id should be `SurrealId` type. +Retrieve a single row by id. This returns `Option[JsonNode]` +Id should be `SurrealId` type. https://itsumura-h.github.io/nim-allographer/query_builder/surreal/surreal_types.html#SurrealId ```nim -let id = SurrealId.new("types:64t0w6gpnye7tdf083ch") -let res = surreal.table("types").find(id).await +let id = SurrealId.new("type:64t0w6gpnye7tdf083ch") +let res = surreal.table("type").find(id).await if res.isSome(): echo res.get() ``` ```nim -DEBUG SELECT * FROM `types` WHERE `id` = ? LIMIT 1 ["types:64t0w6gpnye7tdf083ch"] +DEBUG SELECT * FROM `type` WHERE `id` = ? LIMIT 1 ["type:64t0w6gpnye7tdf083ch"] { "bool":true, "datetime":"2023-06-05T12:08:47Z", "float":3.14, - "id":"types:64t0w6gpnye7tdf083ch", + "id":"type:64t0w6gpnye7tdf083ch", "int":1, "string":"alice" } @@ -130,7 +161,7 @@ user ```nim let res = surreal.table("user").where("name", "=", "alice").first().await if res.isSome(): - echo res.get().pretty() + echo res.get() ``` ```nim @@ -142,7 +173,8 @@ if res.isSome(): ``` ### fetch -Fetch and replace records with the remote record data. +Fetch and replace records with the remote record data. +It is used for retrieve relational tables. auth |id|name| @@ -172,3 +204,291 @@ if alice.isSome(): "name": "alice" } ``` + +## INSERT +[to index](#index) + +https://surrealdb.com/docs/surrealql/statements/insert + +### insert single row +```nim +surreal.table("type").insert(%*{ + "bool":true, + "string": "alice", + "int": 1, + "float": 3.14, + "datetime": now().format("yyyy-MM-dd'T'HH:mm:sszzz") +}) +.await +``` + +### insert rows +```nim +surreal.table("type").insert(%*[ + { + "bool":true, + "string": "alice", + "int": 1, + "float": 3.14, + "datetime": now().format("yyyy-MM-dd'T'HH:mm:sszzz") + }, + { + "bool":false, + "string": "bob", + "int": 2, + "float": 1.11, + "datetime": (now() + initDuration(days=1)).format("yyyy-MM-dd'T'HH:mm:sszzz") + } +]) +.await +``` + +### insertId +```nim +let id:SurrealId = surreal.table("type").insertId(%*{ + "bool":true, + "string": "alice", + "int": 1, + "float": 3.14, + "datetime": now().format("yyyy-MM-dd'T'HH:mm:sszzz") +}) +.await + +echo id.rawId() +``` + +```nim +type:9nxye3dons0juyelv5if +``` + +## UPDATE +[to index](#index) + +https://surrealdb.com/docs/surrealql/statements/update + +```nim +let id = surreal.table("type").insertId(%*{ + "bool":true, + "string": "alice", + "int": 1, + "float": 3.14, + "datetime": now().format("yyyy-MM-dd'T'HH:mm:sszzz") +}) +.await + +surreal.table("type").where("id", "=", id).update(%*{"string": "bob"}).await +let res = surreal.table("type").find(id).await +if res.isSome(): + echo res.get() +``` + +```nim +{ + "bool":true, + "datetime":"2023-06-06T02:34:25Z", + "float":3.14, + "id":"type:hp0aqct78btlcyr1ho06", + "int":1, + "string":"bob" +} +``` + +## DELETE +[to index](#index) + +https://surrealdb.com/docs/surrealql/statements/delete + +## delete all +```nim +let id = surreal.table("type").insertId(%*{ + "bool":true, + "string": "alice", + "int": 1, + "float": 3.14, + "datetime": now().format("yyyy-MM-dd'T'HH:mm:sszzz") +}) +.await + +surreal.table("type").delete().await +echo surreal.table("type").get().await +``` + +```nim +@[] +``` + +## delete row +```nim +surreal.table("type").insert(%*[ + { + "bool":true, + "string": "alice", + "int": 1, + "float": 3.14, + "datetime": now().format("yyyy-MM-dd'T'HH:mm:sszzz") + }, + { + "bool":false, + "string": "bob", + "int": 2, + "float": 1.11, + "datetime": (now() + initDuration(days=1)).format("yyyy-MM-dd'T'HH:mm:sszzz") + } +]) +.await + +let row = surreal.table("type").where("string", "=", "alice").first().await.get() +let rowId = SurrealId.new(row["id"].getStr()) + +surreal.table("type").where("id", "=", rowId).delete().await +echo surreal.table("type").get().await +``` + +```nim +@[ + { + "bool":false, + "datetime":"2023-06-07T03:39:14Z", + "float":"1.11", + "id":"type:y93d6ig6iyrvcez0lc9k", + "int":2, + "string":"bob" + } +] +``` + +## Raw Query +[to index](#INDEX) + +`raw()` returns `RawQuerySurrealDb` type. +You can use `get()`, `exec()` and `info()` for raw query. +`get()` returns all rows of result. +`exec()` executes query and not return any variables. +`info()` executes query and returns all data of response. + +```nim +let define = """ +REMOVE TABLE type; +DEFINE TABLE type SCHEMAFULL; +DEFINE FIELD index ON TABLE type TYPE int; +DEFINE INDEX types_index ON TABLE type COLUMNS index UNIQUE; +DEFINE FIELD bool ON TABLE type TYPE bool; +DEFINE FIELD datetime ON TABLE type TYPE datetime; +DEFINE FIELD float ON TABLE type TYPE float; +DEFINE FIELD int ON TABLE type TYPE int; +DEFINE FIELD string ON TABLE type TYPE string; +""" +surreal.raw(define).exec().await() + +echo surreal.raw("INFO FOR TABLE type").info().await + +>> [ + { + "time":"32.762515ms", + "status":"OK", + "result":{ + "ev":{}, + "fd":{ + "bool":"DEFINE FIELD bool ON type TYPE bool", + "datetime":"DEFINE FIELD datetime ON type TYPE datetime", + "float":"DEFINE FIELD float ON type TYPE float", + "index":"DEFINE FIELD index ON type TYPE int", + "int":"DEFINE FIELD int ON type TYPE int", + "string":"DEFINE FIELD string ON type TYPE string" + }, + "ft":{}, + "ix":{ + "types_index":"DEFINE INDEX types_index ON type FIELDS index UNIQUE" + } + } + } +] + +var rows = surreal.raw("SELECT * FROM type").get().await +let max = rows.len + 1 + +surreal.raw( + """ + CREATE type CONTENT { + index: ?, + bool: true, + datetime: ?, + float: 1.11, + int: 1, + string: "aaa" + } + """, + $max, now().format("yyyy-MM-dd'T'HH:mm:sszzz") +) +.exec() +.await + +rows = surreal.raw("SELECT * FROM type").get().await +echo rows + +>> @[ + { + "bool":true, + "datetime":"2023-06-06T04:01:32Z", + "float":1.11, + "id":"type:f1qxioacts8cydbmchpy", + "index":1, + "int":1, + "string":"aaa" + } +] +``` + +## Aggregates +[to index](#INDEX) + +### count +```nim +surreal.table("user").insert(%*[ + {"name": "alice", "email": "alice@example.com"}, + {"name": "bob", "email": "bob@example.com"}, + {"name": "charlie", "email": "charlie@example.com"}, +]) +.await + +let count = surreal.table("user").count().await +echo count +``` + +```sh +>> 3 +``` + +### max +```nim +surreal.table("user").insert(%*[ + {"name": "alice", "email": "alice@example.com", "index": 1}, + {"name": "bob", "email": "bob@example.com", "index": 2}, + {"name": "charlie", "email": "charlie@example.com", "index": 3}, +]) +.await + +let max = surreal.table("user").max("index").await +echo max +``` + +``` +>> 3 +``` + +### min +```nim +surreal.table("user").insert(%*[ + {"name": "alice", "email": "alice@example.com", "index": 1}, + {"name": "bob", "email": "bob@example.com", "index": 2}, + {"name": "charlie", "email": "charlie@example.com", "index": 3}, +]) +.await + +let min = surreal.table("user").min("index").await +echo min +``` + +``` +>> 1 +``` diff --git a/example/surreal.nim b/example/surreal.nim index da122446..6df09acd 100644 --- a/example/surreal.nim +++ b/example/surreal.nim @@ -7,49 +7,48 @@ import ../src/allographer/query_builder proc main() {.async.} = let surreal = dbOpen(SurrealDb, "test", "test", "user", "pass", "http://surreal", 8000, 10, 30, true, false).await - surreal.raw("DELETE types").exec().await - surreal.raw("DELETE auth").exec().await - surreal.raw("DELETE user").exec().await + surreal.raw("DELETE type").exec().await - surreal.table("types").insert(%*[ + surreal.table("type").insert(%*[ { "bool":true, "string": "alice", "int": 1, "float": 3.14, - "datetime": now().format("yyyy-MM-dd'T'HH:mm:sszzz"), - "null": nil + "datetime": now().format("yyyy-MM-dd'T'HH:mm:sszzz") }, { "bool":false, "string": "bob", "int": 2, "float": 1.11, - "datetime": (now() + initDuration(days=1)).format("yyyy-MM-dd'T'HH:mm:sszzz"), - "null": nil + "datetime": (now() + initDuration(days=1)).format("yyyy-MM-dd'T'HH:mm:sszzz") } ]) .await block : echo "=== get" - echo surreal.table("types").get().await + echo surreal.table("type").get().await block: echo "=== first" - let res = surreal.table("types").first().await + let res = surreal.table("type").first().await if res.isSome(): echo res.get() block: echo "=== find" - let id = SurrealId.new("types:64t0w6gpnye7tdf083ch") - let res = surreal.table("types").find(id).await + let id = SurrealId.new("type:64t0w6gpnye7tdf083ch") + let res = surreal.table("type").find(id).await if res.isSome(): echo res.get() block: echo "=== where" + surreal.raw("DELETE auth").exec().await + surreal.raw("DELETE user").exec().await + let adminId = surreal.table("auth").insertId(%*{"name": "admin"}).await surreal.table("auth").insert(%*{"name": "editor"}).await echo surreal.table("auth").get().await @@ -65,4 +64,146 @@ proc main() {.async.} = if alice.isSome(): echo alice.get().pretty() + block: + echo "=== update" + surreal.raw("DELETE type").exec().await + + let id = surreal.table("type").insertId(%*{ + "bool":true, + "string": "alice", + "int": 1, + "float": 3.14, + "datetime": now().format("yyyy-MM-dd'T'HH:mm:sszzz") + }) + .await + echo id.rawId() + + surreal.table("type").where("id", "=", id).update(%*{"string": "bob"}).await + echo surreal.table("type").find(id).await + + block: + echo "=== delete all" + surreal.raw("DELETE type").exec().await + + let id = surreal.table("type").insertId(%*{ + "bool":true, + "string": "alice", + "int": 1, + "float": 3.14, + "datetime": now().format("yyyy-MM-dd'T'HH:mm:sszzz") + }) + .await + + surreal.table("type").delete().await + echo surreal.table("type").get().await + + block: + echo "=== delete row" + surreal.raw("DELETE type").exec().await + + surreal.table("type").insert(%*[ + { + "bool":true, + "string": "alice", + "int": 1, + "float": 3.14, + "datetime": now().format("yyyy-MM-dd'T'HH:mm:sszzz") + }, + { + "bool":false, + "string": "bob", + "int": 2, + "float": 1.11, + "datetime": (now() + initDuration(days=1)).format("yyyy-MM-dd'T'HH:mm:sszzz") + }]) + .await + + let row = surreal.table("type").where("string", "=", "alice").first().await.get() + let rowId = SurrealId.new(row["id"].getStr()) + + surreal.table("type").where("id", "=", rowId).delete().await + echo surreal.table("type").get().await + + block: + echo "=== raw" + surreal.table("type").delete().await + + let define = """ +REMOVE TABLE type; +DEFINE TABLE type SCHEMAFULL; +DEFINE FIELD index ON TABLE type TYPE int; +DEFINE INDEX types_index ON TABLE type COLUMNS index UNIQUE; +DEFINE FIELD bool ON TABLE type TYPE bool; +DEFINE FIELD datetime ON TABLE type TYPE datetime; +DEFINE FIELD float ON TABLE type TYPE float; +DEFINE FIELD int ON TABLE type TYPE int; +DEFINE FIELD string ON TABLE type TYPE string; +""" + surreal.raw(define).exec().await() + + echo surreal.raw("INFO FOR TABLE type").info().await + + var rows = surreal.raw("SELECT * FROM type").get().await + let max = rows.len + 1 + + surreal.raw(""" + CREATE type CONTENT { + index: ?, + bool: true, + datetime: ?, + float: 1.11, + int: 1, + string: "aaa" + } + """, + $max, now().format("yyyy-MM-dd'T'HH:mm:sszzz")) + .exec() + .await + + rows = surreal.raw("SELECT * FROM type").get().await + echo rows + + block: + echo "=== count" + surreal.table("user").delete().await + + surreal.table("user").insert(%*[ + {"name": "alice", "email": "alice@example.com"}, + {"name": "bob", "email": "bob@example.com"}, + {"name": "charlie", "email": "charlie@example.com"}, + ]) + .await + + let count = surreal.table("user").count().await + echo count + + block: + echo "=== max" + surreal.table("user").delete().await + + surreal.table("user").insert(%*[ + {"name": "alice", "email": "alice@example.com", "index": 1}, + {"name": "bob", "email": "bob@example.com", "index": 2}, + {"name": "charlie", "email": "charlie@example.com", "index": 3}, + ]) + .await + + let max = surreal.table("user").max("index").await + echo max + + block: + echo "=== min" + surreal.table("user").delete().await + + surreal.table("user").insert(%*[ + {"name": "alice", "email": "alice@example.com", "index": 1}, + {"name": "bob", "email": "bob@example.com", "index": 2}, + {"name": "charlie", "email": "charlie@example.com", "index": 3}, + ]) + .await + + let min = surreal.table("user").min("index").await + echo min + + main().waitFor diff --git a/src/allographer/query_builder/surreal/query/grammar.nim b/src/allographer/query_builder/surreal/query/grammar.nim index e0cca0b7..d91d2c22 100644 --- a/src/allographer/query_builder/surreal/query/grammar.nim +++ b/src/allographer/query_builder/surreal/query/grammar.nim @@ -63,7 +63,10 @@ proc where*(self: SurrealDb, column: string, symbol: string, whereSymbolsError ) - self.placeHolder.add($value) + when value.type is SurrealId: + self.placeHolder.add(value.rawId()) + else: + self.placeHolder.add($value) if self.query.hasKey("where") == false: self.query["where"] = %*[{ @@ -114,7 +117,10 @@ proc orWhere*(self: SurrealDb, column: string, symbol: string, whereSymbolsError ) - self.placeHolder.add($value) + when value.type is SurrealId: + self.placeHolder.add(value.rawId()) + else: + self.placeHolder.add($value) if self.query.hasKey("or_where") == false: self.query["or_where"] = %*[{ diff --git a/src/allographer/query_builder/surreal/surreal_types.nim b/src/allographer/query_builder/surreal/surreal_types.nim index 155f70b1..eae82626 100644 --- a/src/allographer/query_builder/surreal/surreal_types.nim +++ b/src/allographer/query_builder/surreal/surreal_types.nim @@ -30,30 +30,31 @@ type type SurrealId* = object table*:string - id*:string + id:string + proc new*(_:type SurrealId):SurrealId = ## create empty surreal id return SurrealId(table:"", id:"") + proc new*(_:type SurrealId, table, id:string):SurrealId = ## .. code-block:: Nim ## let rawId = "user:z7cr4mz474h4ab7rcd6d" ## let table = "user" ## let id = "z7cr4mz474h4ab7rcd6d" ## let surrealId = SureealId.new(table, id) - if table.len == 0: dbError("table cannot be empty") if id.len == 0: dbError("id cannot be empty") return SurrealId(table:table, id:id) + proc new*(_:type SurrealId, rawId:string):SurrealId = ## .. code-block:: Nim ## let rawId = "user:z7cr4mz474h4ab7rcd6d" ## let surrealId = SureealId.new(rawId) - if rawId.len == 0: dbError("rawId cannot be empty") let split = rawId.split(":") @@ -61,17 +62,19 @@ proc new*(_:type SurrealId, rawId:string):SurrealId = let id = split[1] return SurrealId(table:table, id:id) + proc rawId*(self:SurrealId):string = ## .. code-block:: Nim ## let rawId = "user:z7cr4mz474h4ab7rcd6d" ## let surrealId = SureealId.new(rawId) ## surrealId.rawId() == "user:z7cr4mz474h4ab7rcd6d" - return self.table & ":" & self.id + proc `$`*(self:SurrealId):string = return self.id + proc `%`*(self:SurrealId):JsonNode = return %(self.rawId()) diff --git a/tests/test_surreal_query.nim b/tests/test_surreal_query.nim index 351e67a7..71ae2402 100644 --- a/tests/test_surreal_query.nim +++ b/tests/test_surreal_query.nim @@ -24,17 +24,17 @@ suite("surreal type"): let alice = surreal.table("user").where("name", "=", "alice").first().waitFor().get() check aliceId.rawId() == alice["id"].getStr() check aliceId.table == alice["id"].getStr().split(":")[0] - check aliceId.id == alice["id"].getStr().split(":")[1] + check $aliceId == alice["id"].getStr().split(":")[1] let alice2 = SurrealId.new(aliceId.rawId()) check alice2.rawId() == alice["id"].getStr() check alice2.table == alice["id"].getStr().split(":")[0] - check alice2.id == alice["id"].getStr().split(":")[1] + check $alice2 == alice["id"].getStr().split(":")[1] - let alice3 = SurrealId.new(aliceId.table, aliceId.id) + let alice3 = SurrealId.new(aliceId.table, $aliceId) check alice3.rawId() == alice["id"].getStr() check alice3.table == alice["id"].getStr().split(":")[0] - check alice3.id == alice["id"].getStr().split(":")[1] + check $alice3 == alice["id"].getStr().split(":")[1] suite("surreal query"):