Skip to content

Commit

Permalink
Add missing functions (#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhghomon authored Aug 30, 2024
1 parent 218531f commit 378009f
Show file tree
Hide file tree
Showing 23 changed files with 475 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ These functions can be used when working with, and manipulating arrays of data.
<td scope="row" data-label="Function"><a href="#arraydistinct"><code>array::distinct()</code></a></td>
<td scope="row" data-label="Description">Returns the unique items in an array</td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="#arrayfill"><code>array::fill()</code></a></td>
<td scope="row" data-label="Description">Fills an existing array of the same value</td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="#arrayfilter"><code>array::filter()</code></a></td>
<td scope="row" data-label="Description">Filters out values that do not match a pattern</td>
Expand Down Expand Up @@ -114,6 +118,10 @@ These functions can be used when working with, and manipulating arrays of data.
<td scope="row" data-label="Function"><a href="#arrayintersect"><code>array::intersect()</code></a></td>
<td scope="row" data-label="Description">Returns the values which intersect two arrays</td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="#arrayis_empty"><code>array::is_empty()</code></a></td>
<td scope="row" data-label="Description">Checks if an array is empty</td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="#arrayjoin"><code>array::join()</code></a></td>
<td scope="row" data-label="Description">Returns concatenated value of an array with a string in between.</td>
Expand Down Expand Up @@ -166,14 +174,26 @@ These functions can be used when working with, and manipulating arrays of data.
<td scope="row" data-label="Function"><a href="#arraypush"><code>array::push()</code></a></td>
<td scope="row" data-label="Description">Appends an item to the end of an array</td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="#arrayrange"><code>array::range()</code></a></td>
<td scope="row" data-label="Description">Creates a number array from a range (start to end)</td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="#arrayremove"><code>array::remove()</code></a></td>
<td scope="row" data-label="Description">Removes an item at a specific position from an array, supports negative index</td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="#arrayrepeat"><code>array::repeat()</code></a></td>
<td scope="row" data-label="Description">Creates an array of the same value of a given size</td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="#arrayreverse"><code>array::reverse()</code></a></td>
<td scope="row" data-label="Description">Reverses the sorting order of an array</td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="#arrayshuffle"><code>array::shuffle()</code></a></td>
<td scope="row" data-label="Description">Randomly shuffles the contents of an array</td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="#arraysort"><code>array::sort()</code></a></td>
<td scope="row" data-label="Description">Sorts the values in an array in ascending or descending order</td>
Expand All @@ -190,6 +210,10 @@ These functions can be used when working with, and manipulating arrays of data.
<td scope="row" data-label="Function"><a href="#arraysortdesc"><code>array::sort::desc()</code></a></td>
<td scope="row" data-label="Description">Sorts the values in an array in descending order</td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="#arrayswap"><code>array::swap()</code></a></td>
<td scope="row" data-label="Description">Swaps two items in an array</td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="#arraytranspose"><code>array::transpose()</code></a></td>
<td scope="row" data-label="Description">Performs 2d array transposition on two arrays</td>
Expand Down Expand Up @@ -547,6 +571,48 @@ RETURN array::distinct([ 1, 2, 1, 3, 3, 4 ]);

<br />

## `array::fill`

<Since v="v2.0.0" />

The `array::fill` function replaces all values of an array with a new value.

```surql title="API DEFINITION"
array::fill(array, any) -> array
```

The function also accepts a third and a fourth parameter which allows you to replace only a portion of the source array.

```surql title="API DEFINITION"
array::fill(array, any, start: int, end: int) -> array
```

The following example shows this function, and its output, when used in a [`RETURN`](/docs/surrealdb/surrealql/statements/return) statement:

```surql
RETURN array::fill([ 1, 2, 3, 4, 5 ], 10);
[ 10, 10, 10, 10, 10 ]
```

The following example shows how you can use this function with a starting position, and an ending position, which in this example will replace one item from the array:

```surql
RETURN array::fill([ 1, NONE, 3, 4, 5 ], 10, 1, 2);
[ 1, 10, 3, 4, 5 ]
```

The following example shows how you can use this function with starting and ending negative positions, which in this example will replace one item from the array:

```surql
RETURN array::fill([ 1, 2, NONE, 4, 5 ], 10, -3, -2);
[ 1, 2, 10, 4, 5 ]
```

<br />

## `array::filter`

The `array::filter` function filters out values in an array that do not match a pattern, returning only the ones that do match.
Expand Down Expand Up @@ -795,6 +861,31 @@ RETURN array::intersect([1,2,3,4], [3,4,5,6]);

<br />

## `array::is_empty`

<Since v="v2.0.0" />

The `array::is_empty` checks whether the array contains values.

```surql title="API DEFINITION"
array::is_empty(array) -> bool
```
The following example shows this function, and its output, when used in a [`RETURN`](/docs/surrealdb/surrealql/statements/return) statement:

```surql title="An array that contain values"
RETURN array::is_empty([1,2,3,4]);
false
```

```surql title="An empty array"
RETURN array::is_empty([]);
true
```

<br />

## `array::join`

The `array::join` function takes an array and a string as parameters and returns a concatenated string.
Expand Down Expand Up @@ -1126,6 +1217,31 @@ RETURN array::push([1,2,3,4], 5);

<br />

## `array::range`

<Since v="v2.0.0" />

The `array::range` function creates an array of numbers from a given range.

```surql title="API DEFINITION"
array::range(start, end) -> array
```
The following example shows this function, and its output, when used in a [`RETURN`](/docs/surrealdb/surrealql/statements/return) statement:

```surql
RETURN array::range(1, 10);
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
```

```surql
RETURN array::range(3, 2);
[ 3, 4 ]
```

<br />

## `array::remove`

The `array::remove` function removes an item from a specific position in an array, supports negative index.
Expand All @@ -1151,6 +1267,31 @@ RETURN array::remove([1,2,3,4,5], -2);

<br />

## `array::repeat`

<Since v="v2.0.0" />

The `array::repeat` function creates an array of a given size that will contain the same value.

```surql title="API DEFINITION"
array::repeat(any, count) -> array
```
The following example shows this function, and its output, when used in a [`RETURN`](/docs/surrealdb/surrealql/statements/return) statement:

```surql
RETURN array::repeat(1, 10);
[ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 ]
```

```surql
RETURN array::repeat("hello", 2);
[ "hello", "hello" ]
```

<br />

## `array::reverse`

The `array::reverse` function reverses the sorting order of an array.
Expand All @@ -1169,6 +1310,26 @@ RETURN array::reverse([ 1, 2, 3, 4, 5 ]);

<br />

## `array::shuffle`

<Since v="v2.0.0" />

The `array::shuffle` function randomly shuffles the items of an array.

```surql title="API DEFINITION"
array::shuffle(array) -> array
```

The following example shows this function, and its possible output, when used in a [`RETURN`](/docs/surrealdb/surrealql/statements/return) statement:

```surql
RETURN array::shuffle([ 1, 2, 3, 4, 5 ]);
[ 2, 1, 4, 3, 5 ]
```

<br />

## `array::sort`

The `array::sort` function sorts the values in an array in ascending or descending order.
Expand Down Expand Up @@ -1298,6 +1459,53 @@ RETURN array::sort::desc([ 1, 2, 1, null, "something", 3, 3, 4, 0 ]);

<br />

## `array::swap`

<Since v="v2.0.0" />

The `array::swap` swaps two values of an array based on indexes.


```surql title="API DEFINITION"
array::swap(array, from: int, to: int) -> array
```
The following example shows this function, and its output, when used in a [`RETURN`](/docs/surrealdb/surrealql/statements/return) statement:

```surql
RETURN array::swap(["What's", "its", "got", "in", "it", "pocketses?"], 1, 4);
```

```bash title="Output"
[
"What's",
'it',
'got',
'in',
'its',
'pocketses?'
]
```

The following example shows how you can use this function with a positive index, and a negative index, which will swap the first and last element from the array:

```surql
RETURN array::swap([ 1, 2, 3, 4, 5 ], 0, -1);
[ 5, 2, 3, 4, 1 ]
```

An error will be returned if any of the indexes are invalid that informs of range of possible indexes that can be used.

```surql
RETURN array::swap([0,1], 100, 1000000);
```

```bash title="Output"
'Incorrect arguments for function array::swap(). Argument 1 is out of range. Expected a number between -2 and 2'
```

<br />

## `array::transpose`

The `array::transpose` is used to perform 2d array transposition but its behavior in cases of arrays of differing sizes can be best described as taking in multiple arrays and 'layering' them on top of each other.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
sidebar_position: 3
sidebar_label: Bytes functions
title: Bytes functions | SurrealQL
description: These functions can be used when working with bytes.
---

# Bytes functions

These functions can be used when working with bytes in SurrealQL.

<table>
<thead>
<tr>
<th scope="col">Function</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row" data-label="Function"><a href="#byteslen"><code>bytes::len()</code></a></td>
<td scope="row" data-label="Description">Gives the length in bytes</td>
</tr>
</tbody>
</table>

## `bytes::len`

The `bytes::len` function returns the length in bytes of a `bytes` value.


```surql title="API DEFINITION"
bytes::len(bytes) -> int
```

The following example shows this function, and its output, when used in a [`RETURN`](/docs/surrealdb/surrealql/statements/return) statement:

```surql
RETURN [
bytes::len(<bytes>"Simple ASCII string"),
bytes::len(<bytes>"οὐ γὰρ δυνατόν ἐστιν ἔτι καθεύδειν"),
bytes::len(<bytes>"청춘예찬 靑春禮讚")
];
```

```bash title="Output"
[ 19, 67, 25 ]
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 3
sidebar_position: 4
sidebar_label: Count function
title: Count function | SurrealQL
description: These functions can be used when counting field values and expressions.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
---
sidebar_position: 4
sidebar_position: 5
sidebar_label: Crypto functions
title: Crypto functions | SurrealQL
description: These functions can be used when hashing data, encrypting data, and for securely authenticating users into the database.
---

import Since from '@site/src/components/Since'

# Crypto functions

These functions can be used when hashing data, encrypting data, and for securely authenticating users into the database.
Expand All @@ -17,6 +19,10 @@ These functions can be used when hashing data, encrypting data, and for securely
</tr>
</thead>
<tbody>
<tr>
<td scope="row" data-label="Function"><a href="#cryptoblake3"><code>crypto::md5()</code></a></td>
<td scope="row" data-label="Description">Returns the blake3 hash of a value</td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="#cryptomd5"><code>crypto::md5()</code></a></td>
<td scope="row" data-label="Description">Returns the md5 hash of a value</td>
Expand Down Expand Up @@ -68,6 +74,25 @@ These functions can be used when hashing data, encrypting data, and for securely
</tbody>
</table>

## `crypto::blake3`

<Since v="v2.0.0" />

The `crypto::blake3` function returns the blake3 hash of the input value.

```surql title="API DEFINITION"
crypto::blake3(string) -> string
```
The following example shows this function, and its output, when used in a [`RETURN`](/docs/surrealdb/surrealql/statements/return) statement:

```surql
RETURN crypto::blake3("tobie");
'85052e9aab1b67b6622d94a08441b09fd5b7aca61ee360416d70de5da67d86ca'
```

<br />

## `crypto::md5`

The `crypto::md5` function returns the md5 hash of the input value.
Expand Down
Loading

0 comments on commit 378009f

Please sign in to comment.