Skip to content

Commit b91d6bc

Browse files
committed
Docs work + various improvements (#103)
* update documenation to use Table.schema() * fix bug in playground script * allow async cursor.forEach() callbacks * update to error obj v2 + some error docs * fix broken tests * work making logging outputs more structured/readable * lil bit more work making logs less verbose/more relavant * rip out keyTransformer * rip out normalizedSort, replace with codec update * added validation for codec classes * require a default "*" for CollNumRepCfg * catch errors thrown in listeners so they dont prevent bubbling * lot of work documenting http stuff * worlds shittiest way to enforce typescript dependency version * remove now irrelevant part of readme * some renamings and such
1 parent e31aa41 commit b91d6bc

File tree

120 files changed

+3849
-2439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+3849
-2439
lines changed

README.md

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@
2121

2222
## Quickstart
2323

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+
```
2535
2636
Get the *API endpoint* and your *application token* for your Astra DB instance @ [astra.datastax.com](https://astra.datastax.com).
2737
@@ -169,56 +179,6 @@ type Dream = InferTableSchema<typeof DreamsTableSchema>;
169179
})();
170180
```
171181

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-
222182
### Next steps
223183

224184
- More info and usage patterns are given in the ts-doc of classes and methods
@@ -263,9 +223,9 @@ const admin = client.admin();
263223
const dbInfo = databases[0];
264224
console.log(dbInfo.info.name, dbInfo.id, dbInfo.info.region);
265225

266-
// list namespaces for the first database
226+
// list keyspaces for the first database
267227
const dbAdmin = admin.dbAdmin(dbInfo.id, dbInfo.info.region);
268-
console.log(await dbAdmin.listNamespaces());
228+
console.log(await dbAdmin.listKeyspaces());
269229
})();
270230
```
271231

0 commit comments

Comments
 (0)