Back

[SOLVED] how to create Attributes, reading the docs for Client and Server ?

  • 0
  • Databases
renderlux
14 Dec, 2023, 15:19

Quick question how to create Attributes for documents, reading the docs for Client and Server I can't find anything.

I want to set up database, collation and attributes from code, can anyone point me in the right direct.

TL;DR
User wants to know how to create Attributes using the Client and Server documentation. The user shares a code snippet they wrote, and asks if it's the best option. Another user suggests creating a function to create the attributes from an array of objects. The original user also asks if there's a way to process multiple attributes at once. Another user provides a link to the documentation that should have the necessary functions. The original user thanks them and asks how to create attributes for documents in general. Solution: The user can refer to the provided documentation for the necessary functions to create attributes.
Kenny
14 Dec, 2023, 15:37

https://appwrite.io/docs/references/cloud/server-nodejs/databases

This should have all the functions you're looking for.

renderlux
14 Dec, 2023, 15:44

Thanks, don't know how I missed that.

But do you have to do it one by one.

const promise = databases.createIpAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false);

and not a list of Attribute to process all at once?

Kenny
14 Dec, 2023, 15:54

It looks to be that way. I mean, I don't think it would be too terribly hard to create a function yourself that takes in something like an array of objects and creates those attributes from that?

Kenny
14 Dec, 2023, 15:57
TypeScript
async function createAttributes(attributes: Attributes) {
  forEach(const attribute in attributes) {
    switch(attribute.type) {
      case "float":
         await databases.createFloatAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false);
      case "everything else"
         await blah blah blah
    }
  }
}

Not sure if this is the best option but just something I quickly wrote rn.

renderlux
14 Dec, 2023, 15:57

Yep, going have to do that 🙂 Just making sure 100%

renderlux
14 Dec, 2023, 15:57

Thanks for help 🙂

Kenny
14 Dec, 2023, 15:58

No problem! :)

Drake
14 Dec, 2023, 17:14

[SOLVED] how to create Attributes, reading the docs for Client and Server ?

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