You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`YQL` is a language with strict types. This means that a query to `YDB` must be written with an explicit declaration of query parameter types using the `DECLARE`keyword. Also, in some cases, the special `PRAGMA` operator can be used to simplify of the full table path prefix. For example, a query to the table `/local/path/to/tables/seasons` might look like this:
355
+
YQL is a SQL dialect with YDB specific strict types. This is great for performance and correctness, but sometimes can be a bit dauting to express in a query, especially when then need to be parametrized externally from the application side. For instance, when a YDB query needs to be parametrized, each parameter has name and type provided via `DECLARE` statement.
356
+
357
+
Also, because YDB tables reside in virtual filesystem-like structure their names can be quite lengthy. There's a `PRAGMA TablePathPrefix` that can scope the rest of the query inside a given prefix, simplifying table names. For example, a query to the table `/local/path/to/tables/seasons` might look like this:
356
358
357
359
```
358
360
DECLARE $title AS Text;
@@ -362,7 +364,7 @@ FROM `/local/path/to/tables/seasons`
362
364
WHERE title LIKE $title AND views > $views;
363
365
```
364
366
365
-
Using the `PRAGMA`operator, you can simplify the prefix part in the name of all tables involved in the `YQL`-query:
367
+
Using the `PRAGMA`statement, you can simplify the prefix part in the name of all tables involved in the `YQL`-query:
366
368
367
369
```
368
370
PRAGMA TablePathPrefix("/local/path/to/tables/");
@@ -371,15 +373,15 @@ DECLARE $views AS Uint64;
371
373
SELECT season_id FROM seasons WHERE title LIKE $title AND views > $views;
372
374
```
373
375
374
-
`database/sql` driver for `YDB` supports query enrichment for:
376
+
`database/sql` driver for `YDB`(part of [YDB Go SDK](https://github.com/ydb-platform/ydb-go-sdk)) supports query enrichment for:
375
377
376
-
* specifying `TablePathPrefix`,
377
-
*declaring types of parameters,
378
-
*numeric or positional parameters
378
+
* specifying **_TablePathPrefix_**
379
+
***_declaring_** types of parameters
380
+
***_numeric_** or **_positional_** parameters
379
381
380
-
This enrichments of queries can be enabled explicitly on initializing step using connector option `ydb.WithAutoBind(bind)`or connection string parameter `go_query_bind`. By default `database/sql` driver for `YDB`not modifies source queries.
382
+
These query enrichments can be enabled explicitly on the initializing step using connector options or connection string parameter `go_auto_bind`. By default `database/sql` driver for `YDB`doesn’t modify queries.
381
383
382
-
Next example without bindings shows complexity and explicit importing of `ydb-go-sdk` packages:
384
+
The following example without bindings demonstrates explicit working with `YDB` types:
383
385
384
386
```go
385
387
import (
@@ -408,7 +410,11 @@ func main() {
408
410
}
409
411
```
410
412
411
-
This example can be overwritten to easiest over bindings:
413
+
As you can see, this example also required importing of `ydb-go-sdk` packages and working with them directly.
414
+
415
+
With enabled bindings enrichment, the same result can be achieved much easier:
416
+
417
+
- with _**connection string_** params:
412
418
```go
413
419
import (
414
420
"context"
@@ -419,27 +425,49 @@ import (
419
425
420
426
funcmain() {
421
427
var (
422
-
ctx = context.TODO()
423
-
db = sql.Open("ydb", "grpc://localhost:2136/local?"+
0 commit comments