Skip to content

Commit cdb8d43

Browse files
committed
add additional access patterns
1 parent f68dc4a commit cdb8d43

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
# @datastax/astra-ts-client
1+
# @datastax/astra-ts-client
2+
3+
## Getting Started
4+
5+
```typescript
6+
import { AstraDB } from "@datastax/astra-ts-client";
7+
const astraDb = new AstraDB(TOKEN, DATABASE_ID, REGION);
8+
const collection = await astraDb.collection("events");
9+
const results = await collection.countDocuments();
10+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
],
2626
"homepage": "https://github.com/datastax/astra-ts-client",
2727
"license": "Apache-2.0",
28-
"main": "dist/src/index.js",
28+
"main": "dist/index.js",
2929
"mocha": {
3030
"timeout": 30000,
3131
"require": [

src/collections/client.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
// limitations under the License.
1414

1515
import { Db } from './db';
16-
import { createNamespace, parseUri } from './utils';
16+
import {createAstraUri, createNamespace, parseUri} from './utils';
1717
import { HTTPClient } from '@/src/client';
1818
import { logger } from '@/src/logger';
19+
import {Collection} from "./collection";
1920

2021
export interface ClientOptions {
2122
applicationToken?: string;
@@ -79,6 +80,10 @@ export class Client {
7980
return client;
8081
}
8182

83+
async collection(name: string) {
84+
return new Collection(this.httpClient, name);
85+
}
86+
8287
/**
8388
* Connect the MongoClient instance to JSON API (create Namespace automatically when the 'createNamespaceOnConnect' flag is set to true)
8489
* @returns a MongoClient instance
@@ -130,3 +135,11 @@ export class Client {
130135
}
131136

132137
}
138+
139+
export class AstraDB extends Client {
140+
constructor(token: string, dbId: string, region: string, keyspace?: string) {
141+
const keyspaceName = keyspace || "default_keyspace"
142+
const endpoint = createAstraUri(dbId, region, keyspaceName)
143+
super(endpoint, keyspaceName, {isAstra: true, applicationToken: token});
144+
}
145+
}

src/collections/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
export { Client } from './client';
15+
export { Client, AstraDB } from './client';
1616
export { Collection } from './collection';
1717

1818
export {
@@ -27,7 +27,4 @@ export {
2727
DeleteOneOptions
2828
} from './options';
2929

30-
// alias for MongoClient shimming
31-
export { Client as MongoClient } from './client';
32-
3330
export { createAstraUri, createStargateUri } from './utils';

src/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
export * as collections from './collections';
16-
export * as client from './client';
17-
export * as logger from './logger';
15+
export { Collection } from './collections';
16+
export { AstraDB } from './collections/client';
17+
// export * as client from './client';
18+
// export * as logger from './logger';
1819

19-
import { createStargateUri, createAstraUri } from './collections';
20-
export { createStargateUri, createAstraUri };
20+
// import { createStargateUri, createAstraUri } from './collections';
21+
// export { createStargateUri, createAstraUri };

0 commit comments

Comments
 (0)