|
21 | 21 |
|
22 | 22 | ## Quickstart
|
23 | 23 |
|
24 |
| -Use your preferred package manager to install `@datastax/astra-db-ts`. Note that this is not supported in browsers. |
| 24 | +Use your preferred package manager to install `@datastax/astra-db-ts`. |
| 25 | + |
| 26 | +```bash |
| 27 | +npm i @datastax/astra-db-ts # or your favorite package manager's equivalent |
| 28 | +```` |
| 29 | + |
| 30 | +If you're using TypeScript, you must use at least version 5.0.0 to use `astra-db-ts 2.0`, as it uses modern TypeScript features such as `const` type parameters. |
| 31 | +
|
| 32 | +```bash |
| 33 | +npm i typescript@^5.0.0 |
| 34 | +``` |
25 | 35 |
|
26 | 36 | Get the *API endpoint* and your *application token* for your Astra DB instance @ [astra.datastax.com](https://astra.datastax.com).
|
27 | 37 |
|
@@ -169,56 +179,6 @@ type Dream = InferTableSchema<typeof DreamsTableSchema>;
|
169 | 179 | })();
|
170 | 180 | ```
|
171 | 181 |
|
172 |
| -<details> |
173 |
| - <summary><i>Inferring the table schema pre-TS v5.0</i></summary> |
174 |
| - |
175 |
| - Before TypeScript 5.0, there was no support for "const type parameters" (e.g. `f<const T>(t: T): T`) which `Table.schema` relies on. |
176 |
| - |
177 |
| - No worries though—if you're using TypeScript 4.x or below, you can still infer the schema automatically, albeit with less language server support. |
178 |
| - |
179 |
| - Schema object type errors may be non-local and harder to debug, but the code will still work as expected. |
180 |
| - |
181 |
| - ```ts |
182 |
| - const DreamsTableSchema = <const>{ |
183 |
| - columns: { |
184 |
| - id: 'int', |
185 |
| - summary: 'text', |
186 |
| - tags: { type: 'set', valueType: 'text' }, |
187 |
| - vector: { type: 'vector', dimension: 3 }, |
188 |
| - }, |
189 |
| - primaryKey: 'id', |
190 |
| - }; |
191 |
| - |
192 |
| - // Still works, but you need to ensure DreamsTableSchema is a properly typed const object |
193 |
| - type Dream = InferTableSchema<typeof DreamsTableSchema>; |
194 |
| - type DreamPK = InferTablePrimaryKey<typeof DreamsTableSchema>; |
195 |
| - |
196 |
| - (async () => { |
197 |
| - // Necessary to explicitly set the type of the table schema and primary key here |
198 |
| - const table = await db.createTable<Dream, DreamPK>('dreams', { |
199 |
| - definition: DreamsTableSchema, |
200 |
| - ifNotExists: true, |
201 |
| - }); |
202 |
| - })(); |
203 |
| - ``` |
204 |
| - |
205 |
| - If you're using TypeScript 4.9, you can at least use the `satisfies` operator to localize any definition type errors. |
206 |
| - |
207 |
| - ```ts |
208 |
| - const DreamsTableSchema = <const>{ |
209 |
| - columns: { |
210 |
| - id: 'int', |
211 |
| - summary: 'text', |
212 |
| - tags: { type: 'set', valueType: 'text' }, |
213 |
| - vector: { type: 'vector', dimension: 3 }, |
214 |
| - }, |
215 |
| - primaryKey: 'id', |
216 |
| - } satisfies CreateTableDefinition; |
217 |
| - |
218 |
| - type Dream = InferTableSchema<typeof DreamsTableSchema>; |
219 |
| - ``` |
220 |
| -</details> |
221 |
| - |
222 | 182 | ### Next steps
|
223 | 183 |
|
224 | 184 | - More info and usage patterns are given in the ts-doc of classes and methods
|
@@ -263,9 +223,9 @@ const admin = client.admin();
|
263 | 223 | const dbInfo = databases[0];
|
264 | 224 | console.log(dbInfo.info.name, dbInfo.id, dbInfo.info.region);
|
265 | 225 |
|
266 |
| - // list namespaces for the first database |
| 226 | + // list keyspaces for the first database |
267 | 227 | const dbAdmin = admin.dbAdmin(dbInfo.id, dbInfo.info.region);
|
268 |
| - console.log(await dbAdmin.listNamespaces()); |
| 228 | + console.log(await dbAdmin.listKeyspaces()); |
269 | 229 | })();
|
270 | 230 | ```
|
271 | 231 |
|
|
0 commit comments