2025-04-02 18:11:25 +00:00
<!-- Improved compatibility of К началу link: See: https://github.com/othneildrew/Best - README - Template/pull/73 -->
< a id = "readme-top" > < / a >
<!--
*** Thanks for checking out the Best-README-Template. If you have a suggestion
*** that would make this better, please fork the repo and create a pull request
*** or simply open an issue with the tag "enhancement".
*** Don't forget to give the project a star!
*** Thanks again! Now go create something AMAZING! :D
-->
2020-04-30 19:51:09 +08:00
2025-04-02 18:11:25 +00:00
<!-- PROJECT LOGO -->
< br / >
< div align = "center" >
<!-- <a href="https://github.com/othneildrew/Best - README - Template"> -->
< img src = "Logo-Futriix.png" height = 100 > < / img >
< / a >
2025-04-02 18:13:32 +00:00
< h3 align = "center" > Futriix fdx< / h3 >
2025-04-02 18:11:25 +00:00
2025-04-02 18:13:32 +00:00
## Краткая документация модуля Futriix fdx
2025-04-02 18:11:25 +00:00
2025-04-02 18:14:59 +00:00
< / div >
2025-04-02 18:11:25 +00:00
<!-- TABLE OF CONTENTS -->
< br >
< details >
< summary > < b > Содержание< / b > < / summary >
< ol >
< li >
2025-04-02 18:33:14 +00:00
< a href = " #о -модуле" > О модуле</ a > Загрузка файла в Futriix
2025-04-02 18:11:25 +00:00
< / li >
< li >< a href = " #использование " > Использование</ a ></ li >
2025-04-02 18:22:22 +00:00
< li >< a href = " #начало " > Начало</ a ></ li >
2025-04-02 18:33:14 +00:00
< li >< a href = " #загрузка файла в Futriix</li>" > Загрузка файла в Futriix</ a ></ li >
< li >< a href = " #больше примеров" > Больше примеров</ a ></ li >
< li > < a href = "#" > 4< / a > < / li >
2025-04-02 18:22:22 +00:00
2025-04-02 18:11:25 +00:00
< / ol >
< / details >
<!-- ABOUT THE PROJECT -->
## О модуле
Модуль "fdx" позволяет предоставить простой DML (Data Manipulation Language, подмножество языка SQL для манипулирования данными - это подъязык, отвечающий за добавление, редактирование или удаление данных из базы данных. В SQL этому языку соответствуют операторы INSERT, UPDATE, и DELETE ) и DQL (Data Query Language )- это подъязык, отвечающий за чтение или запрос данных из базы данных. В SQL этому языку соответствует оператор SELECT) для манипулирования хэшами в Futriix для пользователей SQL. Он преобразует входной оператор на языке SQL в набор чистых команд Futriix'а . Он не нуждается и не генерирует никаких промежуточных данных, которые занимали бы базы данных. Целевыми данными являются только ваши хэши. Он также предоставляет функцию импорта и экспорта данных из других субд в формате "CSV".
2020-04-30 20:55:22 +08:00
2025-04-02 18:22:22 +00:00
## Использование
2020-05-02 16:28:53 +08:00
```sql
2025-04-02 18:05:59 +00:00
$ futriix-cli
2025-04-02 18:22:22 +00:00
futriix:~> hmset phonebook:0001 name "Ivan Ivanov" tel "812-692-12-34" birth "1982-10-01" pos 3 gender "M"
futriix:~> hmset phonebook:0002 name "Anna Kaverina" tel "812-444-99-11" birth "1009-12-01" pos 1 gender "F"
futriix:~> hmset phonebook:0003 name "Bella Karetnikova" tel "812-682-24-41" birth "2004-01-31" pos 2 gender "F"
futriix:~> hmset phonebook:0004 name "Maxim Levitsky tel "812-669-09-92" birth "2017-06-30" pos 4 gender "M"
2025-04-02 18:04:11 +00:00
futriix:~> dbx select name,tel from phonebook where gender = "F" order by pos desc
2020-04-30 20:24:55 +08:00
1) 1) name
2025-04-02 18:22:22 +00:00
2) "Ivan Ivanov"
2020-04-30 20:24:55 +08:00
3) tel
2025-04-02 18:22:22 +00:00
4) "812-692-12-34"
2020-04-30 20:24:55 +08:00
2) 1) name
2025-04-02 18:22:22 +00:00
2) "Anna Kaverina"
2020-04-30 20:24:55 +08:00
3) tel
2025-04-02 18:22:22 +00:00
4) "812-444-99-11"
2020-05-01 10:33:32 +08:00
```
2025-04-02 18:22:22 +00:00
## Начало
2020-05-01 10:33:32 +08:00
2025-04-02 18:33:14 +00:00
### Скачиваем пакет и собираем бинаный файл:
2020-05-02 16:28:53 +08:00
```sql
2025-04-02 18:33:14 +00:00
$ git clone https://source.futriix.ru/fbx/fbx.git
$ cd fbx/src & & make
2020-05-01 10:33:32 +08:00
```
2025-04-02 18:33:14 +00:00
После успешной компиляции в директории пояаится файл "fbx.so"
2020-05-01 10:33:32 +08:00
2025-04-02 18:33:14 +00:00
### Загрузка файла в Futriix (3 способа)
2020-05-01 10:33:32 +08:00
2025-04-02 18:33:14 +00:00
1. Загрузка модуля через клиента (команднуб строку)
2020-05-02 16:28:53 +08:00
```sql
2025-04-02 18:04:11 +00:00
futriix:~> module load /path/to/dbx.so
2020-05-01 10:33:32 +08:00
```
2025-04-02 18:33:14 +00:00
2. Запуск сервера с параметром "loadmodule"
2020-05-02 16:28:53 +08:00
```sql
2025-04-02 18:33:14 +00:00
$ Valkeys-server --loadmodule /path/to/fbx.so
2020-05-01 10:33:32 +08:00
```
2025-04-02 18:33:14 +00:00
3.Добавление следующей строки в файл конфигурации Futriix "futriix.conf" с последующей перезагрузкой сервера, для применения вновь внесённых изменений через файл конфигурации.
2020-05-02 16:28:53 +08:00
```sql
2025-04-02 18:33:14 +00:00
loadmodule /path/to/fbx.so
2020-05-01 10:33:32 +08:00
```
2025-04-02 18:33:14 +00:00
## Больше примеров
2020-05-01 10:33:32 +08:00
2020-05-03 21:06:10 +08:00
### Select statement
2020-05-01 10:33:32 +08:00
You may specify multiple fields separated by comma
2020-05-02 16:28:53 +08:00
```sql
2025-04-02 18:04:11 +00:00
futriix:~> dbx select name, gender, birth from phonebook
2020-05-01 10:33:32 +08:00
1) 1) name
2) "Betty Joan"
3) gender
4) "F"
5) birth
6) "2019-12-01"
2) 1) name
2) "Mattias Swensson"
3) gender
4) "M"
5) birth
6) "2017-06-30"
3) 1) name
2) "Peter Nelson"
3) gender
4) "M"
5) birth
6) "2019-10-01"
4) 1) name
2) "Bloody Mary"
3) gender
4) "F"
5) birth
6) "2018-01-31"
```
"*" is support
2020-05-02 16:28:53 +08:00
```sql
2025-04-02 18:04:11 +00:00
futriix:~> dbx select * from phonebook where birth > '2019-11-11'
2020-04-30 20:24:55 +08:00
1) 1) "name"
2020-04-30 20:55:22 +08:00
2) "Betty Joan"
2020-04-30 20:24:55 +08:00
3) "tel"
4) "1-444-9999-1112"
2020-04-30 20:55:22 +08:00
5) "birth"
6) "2019-12-01"
7) "pos"
8) "1"
9) "gender"
10) "F"
2020-05-01 10:33:32 +08:00
```
If you want to show the exact keys, you may try rowid()
2020-05-02 16:28:53 +08:00
```sql
2025-04-02 18:04:11 +00:00
futriix:~> dbx select rowid() from phonebook
2020-05-01 10:33:32 +08:00
1) 1) rowid()
2) "phonebook:1588299191-764848276"
2) 1) rowid()
2) "phonebook:1588299202-1052597574"
3) 1) rowid()
2) "phonebook:1588298418-551514504"
4) 1) rowid()
2) "phonebook:1588299196-2115347437"
```
2025-04-02 18:04:11 +00:00
The above is nearly like ValkeyS keys command
2020-05-02 16:28:53 +08:00
```sql
2025-04-02 18:04:11 +00:00
futriix:~> keys phonebook*
2020-05-01 10:33:32 +08:00
1) "phonebook:1588298418-551514504"
2) "phonebook:1588299196-2115347437"
3) "phonebook:1588299202-1052597574"
4) "phonebook:1588299191-764848276"
```
2025-04-02 18:04:11 +00:00
Each record is exactly a hash, you could use raw ValkeyS commands ``hget, hmget or hgetall` ` to retrieve the same content
2020-05-01 10:33:32 +08:00
2020-05-03 22:32:41 +08:00
#### Where clause
2020-05-01 12:33:19 +08:00
Your could specify =, >, < , >=, < =, < >, != or like conditions in where clause. Now the module only support "and" to join multiple conditions.
2020-05-02 16:28:53 +08:00
```sql
2025-04-02 18:04:11 +00:00
futriix:~> dbx select tel from phonebook where name like Son
2020-04-30 20:24:55 +08:00
1) 1) tel
2) "1-888-3333-1412"
2) 1) tel
2) "1-456-1246-3421"
2025-04-02 18:04:11 +00:00
futriix:~> dbx select tel from phonebook where name like Son and pos = 4
2020-05-01 12:33:19 +08:00
1) 1) tel
2) "1-888-3333-1412"
2020-04-30 20:24:55 +08:00
```
2020-04-30 19:51:09 +08:00
2020-05-03 22:32:41 +08:00
#### Order clause
2020-05-01 10:33:32 +08:00
Ordering can be ascending or descending. All sortings are alpha-sort.
2020-05-02 16:28:53 +08:00
```sql
2025-04-02 18:04:11 +00:00
futriix:~> dbx select name, pos from phonebook order by pos asc
2020-05-02 17:36:09 +08:00
1) 1) name
2) "Betty Joan"
3) pos
4) "1"
2) 1) name
2) "Bloody Mary"
3) pos
4) "2"
3) 1) name
2) "Peter Nelson"
3) pos
4) "3"
4) 1) name
2) "Mattias Swensson"
3) pos
4) "4"
2025-04-02 18:04:11 +00:00
futriix:~> dbx select name from phonebook order by pos desc
2020-05-02 17:36:09 +08:00
1) 1) name
2) "Mattias Swensson"
2) 1) name
2) "Peter Nelson"
3) 1) name
2) "Bloody Mary"
4) 1) name
2) "Betty Joan"
```
2020-05-03 22:32:41 +08:00
#### Top clause
2020-05-02 17:36:09 +08:00
```sql
2025-04-02 18:04:11 +00:00
futriix:~> dbx select top 3 name, tel from phonebook order by pos desc
2020-05-02 17:36:09 +08:00
1) 1) name
2) "Mattias Swensson"
3) tel
4) "1-888-3333-1412"
2) 1) name
2) "Peter Nelson"
3) tel
4) "1-456-1246-3421"
3) 1) name
2) "Bloody Mary"
3) tel
4) "1-666-1234-9812"
2025-04-02 18:04:11 +00:00
futriix:~> dbx select top 0 * from phonebook
2020-05-02 17:36:09 +08:00
(empty list or set)
2020-04-30 20:24:55 +08:00
```
2020-05-03 22:32:41 +08:00
#### Into clause for copy hash table
You could create another hash table by into clause.
2020-05-02 16:28:53 +08:00
```sql
2025-04-02 18:04:11 +00:00
futriix:~> dbx select * into testbook from phonebook
2020-05-01 17:33:23 +08:00
1) testbook:1588325407-1751904058
2) testbook:1588325407-1751904059
3) testbook:1588325407-1751904060
4) testbook:1588325407-1751904061
2025-04-02 18:04:11 +00:00
futriix:~> keys testbook*
2020-05-02 16:28:53 +08:00
1) "testbook:1588325407-1751904061"
2) "testbook:1588325407-1751904059"
3) "testbook:1588325407-1751904058"
4) "testbook:1588325407-1751904060"
2025-04-02 18:04:11 +00:00
futriix:~> dbx select * from testbook
2020-05-01 17:33:23 +08:00
1) 1) "name"
2) "Mattias Swensson"
3) "tel"
4) "1-888-3333-1412"
5) "birth"
6) "2017-06-30"
7) "pos"
8) "4"
9) "gender"
10) "M"
2) 1) "name"
2) "Peter Nelson"
3) "tel"
4) "1-456-1246-3421"
5) "birth"
6) "2019-10-01"
7) "pos"
8) "3"
9) "gender"
10) "M"
3) 1) "name"
2) "Bloody Mary"
3) "tel"
4) "1-666-1234-9812"
5) "birth"
6) "2018-01-31"
7) "pos"
8) "2"
9) "gender"
10) "F"
4) 1) "name"
2) "Betty Joan"
3) "tel"
4) "1-444-9999-1112"
5) "birth"
6) "2019-12-01"
7) "pos"
8) "1"
9) "gender"
10) "F"
```
2020-05-03 22:32:41 +08:00
#### Into csv clause for exporting records in csv format
2020-05-03 21:06:10 +08:00
```sql
2025-04-02 18:04:11 +00:00
futriix:~> dbx select * into csv "/tmp/testbook.csv" from phonebook where pos > 2
2020-05-03 22:32:41 +08:00
1) Kevin Louis,111-2123-1233,2009-12-31,6,F
2) Kenneth Cheng,123-12134-123,2000-12-31,5,M
2025-04-02 18:04:11 +00:00
futriix:~> quit
2020-05-03 21:06:10 +08:00
$ cat /tmp/testbook.csv
2020-05-03 22:32:41 +08:00
Kevin Louis,111-2123-1233,2009-12-31,6,F
Kenneth Cheng,123-12134-123,2000-12-31,5,M
2020-05-03 21:06:10 +08:00
$
```
### Delete statement
2020-05-01 12:33:19 +08:00
You may also use Insert and Delete statement to operate the hash. If you does not provide the where clause, it will delete all the records of the specified key prefix. (i.e. phonebook)
2020-05-02 16:28:53 +08:00
```sql
2025-04-02 18:04:11 +00:00
futriix:~> dbx delete from phonebook where gender = F
2020-05-01 10:33:32 +08:00
(integer) 2
2025-04-02 18:04:11 +00:00
futriix:~> dbx delete from phonebook
2020-05-01 10:33:32 +08:00
(integer) 2
2020-04-30 20:24:55 +08:00
```
2020-04-30 20:55:22 +08:00
2020-05-03 21:06:10 +08:00
### Insert statement
2025-04-02 18:04:11 +00:00
The module provides simple Insert statement which same as the function of the ValkeyS command hmset. It will append a random string to your provided key (i.e. phonebook). If operation is successful, it will return the key name.
2020-05-02 16:28:53 +08:00
```sql
2025-04-02 18:04:11 +00:00
futriix:~> dbx insert into phonebook (name,tel,birth,pos,gender) values ('Peter Nelson' ,1-456-1246-3421, 2019-10-01, 3, M)
2020-05-01 10:33:32 +08:00
"phonebook:1588298418-551514504"
2025-04-02 18:04:11 +00:00
futriix:~> dbx insert into phonebook (name,tel,birth,pos,gender) values ('Betty Joan' ,1-444-9999-1112, 2019-12-01, 1, F)
2020-05-01 10:33:32 +08:00
"phonebook:1588299191-764848276"
2025-04-02 18:04:11 +00:00
futriix:~> dbx insert into phonebook (name,tel,birth,pos,gender) values ('Bloody Mary' ,1-666-1234-9812, 2018-01-31, 2, F)
2020-05-01 10:33:32 +08:00
"phonebook:1588299196-2115347437"
2025-04-02 18:04:11 +00:00
futriix:~> dbx insert into phonebook (name,tel,birth,pos,gender) values ('Mattias Swensson' ,1-888-3333-1412, 2017-06-30, 4, M)
2020-05-01 10:33:32 +08:00
"phonebook:1588299202-1052597574"
2025-04-02 18:04:11 +00:00
futriix:~> hgetall phonebook:1588298418-551514504
2020-05-02 16:28:53 +08:00
1) "name"
2) "Peter Nelson"
3) "tel"
4) "1-456-1246-3421"
5) "birth"
6) "2019-10-01"
7) "pos"
8) "3"
9) "gender"
10) "M"
2025-04-02 18:04:11 +00:00
futriix:~>
2020-04-30 20:24:55 +08:00
```
2025-04-02 18:04:11 +00:00
Note that Valkeys requires at least one space after the single and double quoted arguments, otherwise you will get ``Invalid argument(s)` ` error. If you don't want to take care of this, you could quote the whole SQL statement by double quote as below:
2020-05-02 16:28:53 +08:00
```sql
2025-04-02 18:04:11 +00:00
futriix:~> dbx "insert into phonebook (name,tel,birth,pos,gender) values ('Peter Nelson','1-456-1246-3421','2019-10-01',3, 'M')"
2020-04-30 20:24:55 +08:00
```
2020-05-03 22:32:41 +08:00
#### From clause for importing CSV file
2025-04-02 18:04:11 +00:00
The module provides simple import function by specifying from clause in Insert statement. It only support comma deliminated. Please make sure that the specified import file can be accessed by Valkeys server.
2020-05-03 21:06:10 +08:00
```bash
$ cat > /tmp/test.csv < < EOF
"Kenneth Cheng","123-12134-123","2000-12-31","5","M"
"Kevin Louis","111-2123-1233","2009-12-31","6","F"
EOF
2025-04-02 18:04:11 +00:00
$ Valkeys-cli
futriix:~> dbx insert into phonebook (name, tel, birth, pos, gender) from "/tmp/test.csv"
2020-05-03 21:06:10 +08:00
1) "phonebook:1588509697-1579004777"
2) "phonebook:1588509697-1579004778"
2025-04-02 18:04:11 +00:00
futriix:~> dbx select name from phonebook
2020-05-03 21:06:10 +08:00
1) 1) name
2) "Kenneth Cheng"
2) 1) name
2) "Kevin Louis"
2025-04-02 18:04:11 +00:00
futriix:~> dbx delete from phonebook
2020-05-03 21:06:10 +08:00
(integer) 2
2025-04-02 18:04:11 +00:00
futriix:~> quit
2020-05-03 21:06:10 +08:00
$ cat > /tmp/testheader.csv < < EOF
name,tel,birth,pos,gender
"Kenneth Cheng","123-12134-123","2000-12-31","5","M"
"Kevin Louis","111-2123-1233","2009-12-31","6","F"
EOF
2025-04-02 18:04:11 +00:00
$ Valkeys-cli
futriix:~> dbx insert into phonebook from "/tmp/testheader.csv"
2020-05-03 21:06:10 +08:00
1) "phonebook:1588509697-1579004779"
2) "phonebook:1588509697-1579004780"
2025-04-02 18:04:11 +00:00
futriix:~> dbx select name from phonebook
2020-05-03 21:06:10 +08:00
1) 1) name
2) "Kenneth Cheng"
2) 1) name
2) "Kevin Louis"
```
### Issue command from BASH shell
2020-05-02 16:28:53 +08:00
```sql
2025-04-02 18:04:11 +00:00
$ Valkeys-cli dbx select "*" from phonebook where gender = M order by pos desc
2020-05-01 10:33:32 +08:00
1) 1) "name"
2) "Mattias Swensson"
3) "tel"
4) "1-888-3333-1412"
5) "birth"
6) "2017-06-30"
7) "pos"
8) "4"
9) "gender"
10) "M"
2) 1) "name"
2) "Peter Nelson"
3) "tel"
4) "1-456-1246-3421"
5) "birth"
6) "2019-10-01"
7) "pos"
8) "3"
9) "gender"
10) "M"
2025-04-02 18:04:11 +00:00
$ Valkeys-cli dbx select name from phonebook where tel like 9812
2020-05-01 10:33:32 +08:00
1) 1) name
2) "Bloody Mary"
```
Note that "*" requires double quoted otherwise it will pass all the filename in current directory. Of course you could quote the whole SQL statement.
2020-05-02 16:28:53 +08:00
```sql
2025-04-02 18:04:11 +00:00
$ Valkeys-cli dbx "select * from phonebook where gender = M order by pos desc"
2020-05-01 10:33:32 +08:00
```
2020-04-30 20:24:55 +08:00
## Compatibility
2025-04-02 18:04:11 +00:00
ValkeyS v4.0
2020-04-30 20:24:55 +08:00
## License
MIT
2025-04-02 18:00:10 +00:00