Giter VIP home page Giter VIP logo

astrajs's People

Contributors

cahllagerfeld avatar gstachni avatar kidrecursive avatar synedra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

astrajs's Issues

How do we increment atomic values?

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

??

Request failed with status code 404 with REST API

Hello,

  • The following queries work fine using the Document API:
    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?

  • The following 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

Created collections not reflecting in db

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

Add TypeScript types

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.

Production error: Error: @astrajs/rest: baseUrl required

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

Error handling in Document API

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.

Document API does not work with Next.js API Routes

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

No operation available for full or partial text search

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

pageState property not available in response

When using the nodejs library for searching documents, the pageState property is not returned. Without this property you can not page a larger result set. It is available via the API, please see attached

image

Delete always returns null-response

 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

image

This makes it hard to react if the deletion was successfull or not

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.