Skip to content

Commit

Permalink
Update Documentations for Cast and TypesTable
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Nov 9, 2024
1 parent a50408b commit 47fe801
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/expression/case.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### Case expression

Case expression is similar to Switch Expression in many languages, it's return the value of the first branch that has condition evaluated to true, if not branch found it will return the default value

```sql
Expand Down
29 changes: 29 additions & 0 deletions docs/expression/cast.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### Cast expression

In GitQL there are two types of casting, Explicit and Implicit casting

#### Implicit Casting

Implicit casting is performed without the need from you to write cast operator or function for example

```sql
SELECT True = 't'
```

In this case the engine perform implicit cast from Text 't' to become boolean 'true' so it's end up with

```sql
SELECT True = True
```

The same is performed when you write Date, Time or DateTime as String and pass it to function that accept Date.

#### Explicit Casting

Implicit casting can handle some cases when the value is const and has specific pattern, but in some cases you want for example
to cast Float to Int or Int to Float after the value is evaluated or provided from real data, in this case you need to explicit ask the engine
to case this value to another type, for example

```SQL
SELECT CAST(commits_count AS Real);
```
1 change: 1 addition & 0 deletions docs/expression/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ GitQL Expressions
- [Binary expressions](binary.md).
- [Unary expressions](unary.md).
- [Case expression](case.md).
- [Cast expression](cast.md)
- [Array expression](array.md).
- [Access Member](access.md).
20 changes: 19 additions & 1 deletion docs/sdk/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,22 @@ impl DataType for IntPairType {
}
```

Now if we create a new Function with Signature that accept IntPair and we pass Int, it will report an error, but now we created a Type but to create a Value with this type we need to create a Custom Value too ([Creating the IntPairValue as Custom value](values.md)).
Now if we create a new Function with Signature that accept IntPair and we pass Int, it will report an error, but now we created a Type but to create a Value with this type we need to create a Custom Value too ([Creating the IntPairValue as Custom value](values.md)).

### Register your type in TypesTable

If you want to support using your type in explicit casting feature, for example

```SQL
SELECT CAST(value AS IntPairType)
```

You must register your type to the TypesTable component and pass it to the `Environment` for example

```rust
let types_table = TypesTable::new();
types_table.register("intpair", Box::new(IntPairType));

let env = Environment::new();
env.register_types_table(types_table);
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ nav:
- Unary: expression/unary.md
- Binary: expression/binary.md
- Case: expression/case.md
- Cast: expression/cast.md
- Access Member: expression/access.md
- STD Functions and Operators:
- "functions/index.md"
Expand Down

0 comments on commit 47fe801

Please sign in to comment.