Back

elements update in enum attribute

  • 0
  • Databases
  • Self Hosted
  • Web
driver
25 Apr, 2023, 08:57

How can I add programmatically a new element into an existing enum attribute that is not empty? I am using node sdk.

TL;DR
The user is asking for confirmation on when the appwrite cloud will use the newer version. The user is also experiencing an error when using the `databases.updateEnumAttribute` function, which is not recognized as a function. They are also asking for help on how to programmatically add a new element into an existing enum attribute using the node SDK. Solution: 1. The user is advised to build their own REST or GraphQL client to take advantage of the new features immediately. 2. The user can refer to the Appwrite SDK for Node.js documentation for information on the differences between version 1.2.x and 1.3
driver
25 Apr, 2023, 09:20

databases.updateEnumAttribute gives me this error "databases.updateEnumAttribute is not a function". Could this be a bug?

driver
25 Apr, 2023, 09:23

I am using appwrite cloud

Bouahaza
25 Apr, 2023, 13:35

@driver can you give whole code plz. It is difficult to help without more information

driver
25 Apr, 2023, 13:44

import { Client, Databases } from "node-appwrite";

export default async function handler(req, res) { const client = new Client(); client .setEndpoint(process.env.APPWRITE_ENDPOINT) .setProject(process.env.APPWRITE_PROJECT_ID) .setKey(process.env.APPWRITE_DATABASE_API_KEY);

const database = new Databases(client);

const databaseId = process.env.APPWRITE_DATABASE_ID_USERS; const collectionId = process.env.APPWRITE_DATABASE_COLLECTION_ID_POSITIONS; const data = req.body;

if (req.method === "POST") { try { console.log(data.categoryList); // ["Academic", "Technican", "Admin", "Test"] //test is a newly added enum by clinet const response = await database.updateEnumAttribute( databaseId, collectionId, "category", data.categoryList, true );

TypeScript
  res.status(200).json(response); // nothing
} catch (error) {
  console.log(error.message); // error database.updateEnumAttribute is not a function
  res.status(500).json({ error: error.message });
}

} }

Bouahaza
25 Apr, 2023, 13:46

Tips : you can format your code with : https://support.discord.com/hc/en-us/articles/210298617-Markdown-Text-101-Chat-Formatting-Bold-Italic-Underline-#h_01GY0DAKGXDEHE263BCAYEGFJA

TypeScript
import { Client, Databases } from "node-appwrite";

export default async function handler(req, res) {
  const client = new Client();
  client
    .setEndpoint(process.env.APPWRITE_ENDPOINT)
    .setProject(process.env.APPWRITE_PROJECT_ID)
    .setKey(process.env.APPWRITE_DATABASE_API_KEY);

  const database = new Databases(client);

  const databaseId = process.env.APPWRITE_DATABASE_ID_USERS;
  const collectionId = process.env.APPWRITE_DATABASE_COLLECTION_ID_POSITIONS;
  const data = req.body;

  if (req.method === "POST") {
    try {
      console.log(data.categoryList); // ["Academic", "Technican", "Admin", "Test"] //test is a newly added enum by clinet
      const response = await database.updateEnumAttribute(
        databaseId,
        collectionId,
        "category",
        data.categoryList,
        true
      );

      res.status(200).json(response); // nothing
    } catch (error) {
      console.log(error.message); // error database.updateEnumAttribute is not a function
      res.status(500).json({ error: error.message });
    }
  }
}
driver
25 Apr, 2023, 13:47

thanks, I am using nextjs

Bouahaza
25 Apr, 2023, 13:48

1.3 isn't already implemented on nodejs sdk, so you havn't all update endpoint, etc..

Bouahaza
25 Apr, 2023, 13:49

Check diff between

Bouahaza
25 Apr, 2023, 13:49

and

driver
25 Apr, 2023, 13:50

Okay, I see. Thanks

Bouahaza
25 Apr, 2023, 13:50

I think that's where it comes from. But prefer a confirmation from an appwrite staff @Steven

Bouahaza
25 Apr, 2023, 13:51
Bouahaza
25 Apr, 2023, 13:51
Bouahaza
25 Apr, 2023, 13:52

I suggest you to build your own rest or graphql client

Bouahaza
25 Apr, 2023, 13:52

That's what we did, to take advantage of the new features immediately

joeyouss
25 Apr, 2023, 14:35

Thank you for the help @Bouahaza

driver
26 Apr, 2023, 06:15

do you have an idea when appwrite cloud will use the newer version?!

Bouahaza
26 Apr, 2023, 13:18

Not know, when beta closed ?

Bouahaza
26 Apr, 2023, 13:37

1.3 merged on master branch (https://github.com/appwrite/appwrite/pull/5432) So it should happen soon

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more