datastax / astrajs Goto Github PK
View Code? Open in Web Editor NEWA monorepo containing tools for interacting with DataStax Astra and Stargate
Home Page: https://docs.astra.datastax.com/docs/astra-collection-client
License: Apache License 2.0
A monorepo containing tools for interacting with DataStax Astra and Stargate
Home Page: https://docs.astra.datastax.com/docs/astra-collection-client
License: Apache License 2.0
Hi,
As a REST client, it is normal for users to prefer any fetch libraries, not only axios. It would be better if it @astra/rest had this kinda custom fetch library using option.
Correct URL should be https://docs.datastax.com/en/astra-serverless/docs/quickstart/qs-rest.html in the REST README
I couldn't find anything regarding updating a single value through incrementing or decrementing
user_table{
id
likes
}
Eg : likes+1 or likes-1
If I do this operation as getting() value then update() , what happens if another user tries to update in at the same time and my update happens on the value I got before other user's update and only after the other user did update.
Eg :
User1 GET (data : like=0)
User2 GET (data : like=0)
User1 UPDATE (data : like=1)
User2 UPDATE (data : like=1)
Finally like=1 instead of 2
??
Hello,
const restClient = await createClient({
astraDatabaseId: process.env.ASTRA_DB_ID,
astraDatabaseRegion: process.env.ASTRA_DB_REGION,
applicationToken: process.env.ASTRA_DB_APPLICATION_TOKEN
});
const basePath = `/api/rest/v2/namespaces/${process.env.ASTRA_DB_KEYSPACE}/collections/users`;
const { data, status } = await restClient.get(`${basePath}`, {});
The equivalent requests should return the same results using basePath
(where the members
here is a table, and users
is a collection):
const basePath = `/api/rest/v2/keyspaces/${process.env.ASTRA_DB_KEYSPACE}/members`;
The docs uses the path /collections/members
which throws the error: Request failed with status code 404
... right?
1- The first request returns only one document, shouldn't be returning all documents?
axios
requests work fine for both queries (Document API & REST API): const axios = require('axios');
//...
let members = [];
const instance = axios.create({
// Document API
// baseURL: `https://${process.env.ASTRA_DB_ID}-${process.env.ASTRA_DB_REGION}.apps.astra.datastax.com/api/rest/v2/namespaces/${process.env.ASTRA_DB_KEYSPACE}/collections/`,
// REST API
baseURL: `https://${process.env.ASTRA_DB_ID}-${process.env.ASTRA_DB_REGION}.apps.astra.datastax.com/api/rest/v2/keyspaces/${process.env.ASTRA_DB_KEYSPACE}/`,
timeout: 30000,
headers: {
'X-Cassandra-Token': process.env.ASTRA_DB_APPLICATION_TOKEN,
'Content-Type': 'application/json'
}
})
// members = await instance.get('users') // Document API (only one document returned)
// members = await instance.get('users/5ea53e52-dd0c-49af-82c2-f3e210530e2f') // Document API
members = await instance.get('members/5ea53e52-dd0c-49af-82c2-f3e210530e2f') // REST API
.then((results) => {
return results.data;
});
2- Where users
is a document (no predefined schema), and members
is a cassandra table (schema previously defined), however, in both queries there is no way to get the list of collection (or rows), they always return only the first document (unless the id specified), is there any way to retrieve all rows?
P.S. The results.data
contains data
as an array of object, so we you must use result.data.data
to get the array back from results which is weird, is that behavior expected?
Regards
All of the tests in rest.test.js are testing the Documents API (/namespaces
) instead of the REST API (/keyspaces
).
Hi Chris,
I've created a Next.js api route that creates a user in a users collection using the document api. I also have an api route that gets all users and displays them.
I have realised that when I create a new user the users is not always shown on the get users api routes. I have logged into my Datastax account and the new users information is not reflected in the CQL terminal when I query the users collection.
What's interesting is approx 1/5 users reflects on my get users route (and in the Datastax CQL terminal). In the api routes I have both the connection to the database and the create function wrapped in seperate try catch block and I am receiving not errors.
What is even more interesting is that I have an if check in the api route to see if the email entered is already in use prior to a new user being created, when I try and reuse one of the emails from the accounts that I cannot see on the get route, I hit my custom response "Email already in use".
Do you have any idea why this could be? I have been creating many usres with random strings quickly as I'm testing a custom stripe sign up flow.
Thanks,
Adam
Something similar to:
declare module "@astrajs/rest" {
import { AxiosRequestConfig } from "axios";
interface AstraClientOptions {
configFile?: string;
configSection?: string;
baseApiPath?: string;
baseUrl?: string;
authUrl?: string;
authToken?: string;
applicationToken?: string;
autoReconnect?: boolean;
getAuthToken?: () => Promise<string>;
setAuthToken?: (authToken: string) => Promise<void>;
username?: string;
password?: string;
debug?: boolean;
authHeaderName?: string;
astraDatabaseId?: string;
astraDatabaseRegion?: string;
}
interface AstraClient extends AstraClientOptions {
get: (
path: string,
options?: AxiosRequestConfig
) => Promise<{ status: number; data: any }>;
post: (
path: string,
data: any,
options?: AxiosRequestConfig
) => Promise<{ status: number; data: any }>;
put: (
path: string,
data: any,
options?: AxiosRequestConfig
) => Promise<{ status: number; data: any }>;
patch: (
path: string,
data: any,
options?: AxiosRequestConfig
) => Promise<{ status: number; data: any }>;
delete: (
path: string,
options?: AxiosRequestConfig
) => Promise<{ status: number; data: any }>;
}
export function createClient(
options: AstraClientOptions
): Promise<AstraClient>;
export function axiosRequest(
options: AxiosRequestConfig & {
authToken?: string;
applicationToken?: string;
authHeaderName?: string;
}
): Promise<{ status: number; data: any }>;
}
Of course types could be improved further, but this at least offers a first step.
Disclaimer: Copilot chat might have or might have not generated this dts file.
Hello,
I've just pushed my first app to Vercel. My serverless functions are working perfectly in dev but not in production. In the functions log i am getting the error: ERROR Error: @astrajs/rest: baseUrl required for initialization. All of my env variables are uploaded to Vercel, do you have any idea what could be causing this?
Thanks,
Adam
Hello,
Customer has suggested that it would be helpful if there is some sort of BaseModel that they can inherit from with proper error handling in the Collections NPM package. Could you please have a look.
Thanks.
Hello,
I am unable to get the document api to work with the Next.js api routes, I can get it to work in a node environment or using Netlify Functions, but not using Next.js API routes.
Here us the error I am receiving:
Error: @astrajs/rest: baseUrl required for initialization
Any help would be much appreciated.
Thanks,
Adam
I was trying to implement search query so i was not able to find the implementation of full text search or partial text search using collection api, Please help me to implement small search query using @astra/collections or rest api's.
Thank you
async delete(path) {
const response = await this.restClient.delete(`${this.basePath}/${path}`);
if (response.status === 204) {
return response.data;
}
return null;
}
}
In the collection package null
is returned if the response is not 204
The problem is that Stargate returns a null
-Response as well if the status code is 204
This makes it hard to react if the deletion was successfull or not
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.