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
[](https://github.com/avelino/awesome-go#database-drivers)
9
9
10
-
Go driver for [Azure Cosmos DB SQL API](https://azure.microsoft.com/en-us/services/cosmos-db/) which can be used with the standard [database/sql](https://golang.org/pkg/database/sql/) package. A REST client for [Azure Cosmos DB SQL API](https://azure.microsoft.com/en-us/services/cosmos-db/) is also included.
10
+
Go driver for [Azure Cosmos DB SQL API](https://azure.microsoft.com/services/cosmos-db/) which can be used with the standard [database/sql](https://golang.org/pkg/database/sql/) package. A REST client is also included.
-`AccountEndpoint`: (required) endpoint to access Cosmos DB. For example, the endpoint for Azure Cosmos DB Emulator running on local is `https://localhost:8081/`.
43
-
-`AccountKey`: (required) account key to authenticate.
44
-
-`TimeoutMs`: (optional) operation timeout in milliseconds. Default value is `10 seconds` if not specified.
45
-
-`Version`: (optional) version of Cosmos DB to use. Default value is `2018-12-31` if not specified. See: https://docs.microsoft.com/en-us/rest/api/cosmos-db/#supported-rest-api-versions.
46
-
-`AutoId`: (optional, available since [v0.1.2](RELEASE-NOTES.md)) see [auto id](#auto-id) session.
47
-
-`InsecureSkipVerify`: (optional, available since [v0.1.4](RELEASE-NOTES.md)) if `true`, disable CA verification for https endpoint (useful to run against test/dev env with local/docker Cosmos DB emulator).
48
-
49
-
### Known issues
50
-
51
-
**`GROUP BY` combined with `ORDER BY` is not supported**
52
-
53
-
Azure Cosmos DB does not support `GROUP BY` combined with `ORDER BY` yet. You will receive the following error message:
54
-
55
-
> 'ORDER BY' is not supported in presence of GROUP BY.
56
-
57
-
**Cross-partition queries**
58
-
59
-
When documents are spanned across partitions, they must be fetched from multiple `PkRangeId` and then merged to build
60
-
the final result. Due to this behaviour, some cross-partition queries might not work as expected.
14
+
Summary of supported SQL statements:
61
15
62
-
-*Paging cross-partition `OFFSET...LIMIT` queries using `max-count-item`*:<br>
63
-
Since documents must be fetched from multiple `PkRangeId`, the result is nondeterministic.
64
-
Moreover, calls to `RestClient.QueryDocumentsCrossPartition(...)` and `RestClient.QueryDocuments(...)` without
65
-
pagination (i.e. set `MaxCountItem=0`) may yield different results.
16
+
|Statement|Syntax|
17
+
|---------|-----------|
18
+
|Create a new database |`CREATE DATABASE [IF NOT EXISTS] <db-name>`|
19
+
|Change database's throughput |`ALTER DATABASE <db-name> WITH RU/MAXRU=<ru>`|
20
+
|Delete an existing database |`DROP DATABASE [IF EXISTS] <db-name>`|
21
+
|List all existing databases |`LIST DATABASES`|
22
+
|Create a new collection |`CREATE COLLECTION [IF NOT EXISTS] [<db-name>.]<collection-name> <WITH [LARGE]PK=partitionKey>`|
23
+
|Change collection's throughput |`ALTER COLLECTION [<db-name>.]<collection-name> WITH RU/MAXRU=<ru>`|
24
+
|Delete an existing collection |`DROP COLLECTION [IF EXISTS] [<db-name>.]<collection-name>`|
25
+
|List all existing collections in a database|`LIST COLLECTIONS [FROM <db-name>]`|
26
+
|Insert a new document into collection |`INSERT INTO [<db-name>.]<collection-name> ...`|
27
+
|Insert or replace a document |`UPSERT INTO [<db-name>.]<collection-name> ...`|
28
+
|Delete an existing document |`DELETE FROM [<db-name>.]<collection-name> WHERE id=<id-value>`|
29
+
|Update an existing document |`UPDATE [<db-name>.]<collection-name> SET ... WHERE id=<id-value>`|
30
+
|Query documents in a collection |`SELECT [CROSS PARTITION] ... FROM <collection-name> ... [WITH database=<db-name>]`|
66
31
67
-
-*Paging cross-partition `ORDER BY` queries with `max-count-item`*:<br>
68
-
Due to the fact that documents must be fetched from multiple `PkRangeId`, rows returned from calls to
69
-
`RestClient.QueryDocuments(...)` might not be in the expected order.<br>
70
-
*Workaround*: if you can afford the memory, use `RestClient.QueryDocumentsCrossPartition(...)` or
71
-
`RestClient.QueryDocuments(...)` without pagination (i.e. set `MaxCountItem=0`).
32
+
See [supported SQL statements](SQL.md) for details.
72
33
73
-
-*Paging `SELECT DISTINCT` queries with `max-count-item`*:<br>
74
-
Due to the fact that documents must be fetched from multiple `PkRangeId`, rows returned from calls to
75
-
`RestClient.QueryDocuments(...)` might be duplicated.<br>
76
-
*Workaround*: if you can afford the memory, use `RestClient.QueryDocumentsCrossPartition(...)` or
77
-
`RestClient.QueryDocuments(...)` without pagination (i.e. set `MaxCountItem=0`).
78
-
79
-
-*`GROUP BY` combined with `max-count-item`*:<br>
80
-
Due to the fact that documents must be fetched from multiple `PkRangeId`, the result returned from calls to
81
-
`RestClient.QueryDocuments(...)` might not be as espected.<br>
82
-
*Workaround*: if you can afford the memory, use `RestClient.QueryDocumentsCrossPartition(...)` or
83
-
`RestClient.QueryDocuments(...)` without pagination (i.e. set `MaxCountItem=0`).
34
+
> Azure Cosmos DB SQL API currently supports only [SELECT statement](https://learn.microsoft.com/azure/cosmos-db/nosql/query/select).
35
+
> `gocosmos` implements other statements by translating the SQL statement to [REST API calls](https://learn.microsoft.com/rest/api/cosmos-db/).
-`AccountEndpoint`: (required) endpoint to access Cosmos DB. For example, the endpoint for Azure Cosmos DB Emulator running on local is `https://localhost:8081/`.
116
78
-`AccountKey`: (required) account key to authenticate.
117
79
-`TimeoutMs`: (optional) operation timeout in milliseconds. Default value is `10 seconds` if not specified.
118
-
-`Version`: (optional) version of Cosmos DB to use. Default value is `2018-12-31` if not specified. See: https://docs.microsoft.com/en-us/rest/api/cosmos-db/#supported-rest-api-versions.
80
+
-`Version`: (optional) version of Cosmos DB to use. Default value is `2018-12-31` if not specified. See: https://learn.microsoft.com/rest/api/cosmos-db/#supported-rest-api-versions.
119
81
-`DefaultDb`: (optional, available since [v0.1.1](RELEASE-NOTES.md)) specify the default database used in Cosmos DB operations. Alias `Db` can also be used instead of `DefaultDb`.
120
82
-`AutoId`: (optional, available since [v0.1.2](RELEASE-NOTES.md)) see [auto id](#auto-id) session.
121
83
-`InsecureSkipVerify`: (optional, available since [v0.1.4](RELEASE-NOTES.md)) if `true`, disable CA verification for https endpoint (useful to run against test/dev env with local/docker Cosmos DB emulator).
122
84
123
85
### Auto-id
124
86
125
-
Azure Cosmos DB requires each document has a [unique ID](https://docs.microsoft.com/en-us/rest/api/cosmos-db/documents) that identifies the document.
87
+
Azure Cosmos DB requires each document has a [unique ID](https://learn.microsoft.com/rest/api/cosmos-db/documents) that identifies the document.
126
88
When creating new document, if value for the unique ID field is not supplied `gocosmos` is able to generate one automatically. This feature is enabled
127
-
by specifying setting `AutoId=true` in the connection string (for REST client) or Data Source Name (for `database/sql` driver). If not specified, default
89
+
by specifying setting `AutoId=true` in the Data Source Name (for `database/sql` driver) or the connection string (for REST client). If not specified, default
128
90
value is `AutoId=true`.
129
91
130
92
_This settings is available since [v0.1.2](RELEASE-NOTES.md)._
@@ -145,53 +107,94 @@ rows from Cosmos DB. Thus, some limitations:
145
107
146
108
-`OFFSET...LIMIT` without `ORDER BY`:
147
109
148
-
## Features
110
+
## REST client
149
111
150
112
The REST client supports:
151
113
- Database: `Create`, `Get`, `Delete`, `List` and change throughput.
152
114
- Collection: `Create`, `Replace`, `Get`, `Delete`, `List` and change throughput.
153
115
- Document: `Create`, `Replace`, `Get`, `Delete`, `Query` and `List`.
-`AccountEndpoint`: (required) endpoint to access Cosmos DB. For example, the endpoint for Azure Cosmos DB Emulator running on local is `https://localhost:8081/`.
157
+
-`AccountKey`: (required) account key to authenticate.
158
+
-`TimeoutMs`: (optional) operation timeout in milliseconds. Default value is `10 seconds` if not specified.
159
+
-`Version`: (optional) version of Cosmos DB to use. Default value is `2018-12-31` if not specified. See: https://learn.microsoft.com/rest/api/cosmos-db/#supported-rest-api-versions.
160
+
-`AutoId`: (optional, available since [v0.1.2](RELEASE-NOTES.md)) see [auto id](#auto-id) session.
161
+
-`InsecureSkipVerify`: (optional, available since [v0.1.4](RELEASE-NOTES.md)) if `true`, disable CA verification for https endpoint (useful to run against test/dev env with local/docker Cosmos DB emulator).
162
+
163
+
### Known issues
164
+
165
+
**`GROUP BY` combined with `ORDER BY` is not supported**
166
+
167
+
Azure Cosmos DB does not support `GROUP BY` combined with `ORDER BY` yet. You will receive the following error message:
168
+
169
+
> 'ORDER BY' is not supported in presence of GROUP BY.
170
+
171
+
**Cross-partition queries**
172
+
173
+
When documents are spanned across partitions, they must be fetched from multiple `PkRangeId` and then merged to build
174
+
the final result. Due to this behaviour, some cross-partition queries might not work as expected.
175
+
176
+
-*Paging cross-partition `OFFSET...LIMIT` queries using `max-count-item`*:<br>
177
+
Since documents must be fetched from multiple `PkRangeId`, the result is nondeterministic.
178
+
Moreover, calls to `RestClient.QueryDocumentsCrossPartition(...)` and `RestClient.QueryDocuments(...)` without
179
+
pagination (i.e. set `MaxCountItem=0`) may yield different results.
192
180
193
-
> Azure Cosmos DB SQL API currently supports only [SELECT statement](https://docs.microsoft.com/en-us/azure/cosmos-db/sql-query-select).
194
-
> `gocosmos` implements other statements by translating the SQL statement to REST API call to [Azure Cosmos DB REST API](https://docs.microsoft.com/en-us/rest/api/cosmos-db/).
181
+
-*Paging cross-partition `ORDER BY` queries with `max-count-item`*:<br>
182
+
Due to the fact that documents must be fetched from multiple `PkRangeId`, rows returned from calls to
183
+
`RestClient.QueryDocuments(...)` might not be in the expected order.<br>
184
+
*Workaround*: if you can afford the memory, use `RestClient.QueryDocumentsCrossPartition(...)` or
185
+
`RestClient.QueryDocuments(...)` without pagination (i.e. set `MaxCountItem=0`).
186
+
187
+
-*Paging `SELECT DISTINCT` queries with `max-count-item`*:<br>
188
+
Due to the fact that documents must be fetched from multiple `PkRangeId`, rows returned from calls to
189
+
`RestClient.QueryDocuments(...)` might be duplicated.<br>
190
+
*Workaround*: if you can afford the memory, use `RestClient.QueryDocumentsCrossPartition(...)` or
191
+
`RestClient.QueryDocuments(...)` without pagination (i.e. set `MaxCountItem=0`).
192
+
193
+
-*`GROUP BY` combined with `max-count-item`*:<br>
194
+
Due to the fact that documents must be fetched from multiple `PkRangeId`, the result returned from calls to
195
+
`RestClient.QueryDocuments(...)` might not be as espected.<br>
196
+
*Workaround*: if you can afford the memory, use `RestClient.QueryDocumentsCrossPartition(...)` or
197
+
`RestClient.QueryDocuments(...)` without pagination (i.e. set `MaxCountItem=0`).
0 commit comments