Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Collection and Attributes in Database #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions helpers/setup.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const sdk = require('node-appwrite');

const config = {
project: '5d8fa6deefd05',
endpoint: 'https://localhost/v1',
key: '1589eb89e0c0153892c68867ea44137581a7a91390668ab1966a9c3a30a4d9ace58de90b3eaf61c0eae3f35e886b3d01cc8a674caf630c25a4428021ba0697cca5047b42bafb6710911e88fb1553d2833a221a94d2dc6fb55b7e500bc7873c4f09aab939e47aa959d55a972beacec8f7b86852b6842f4ca606908dea9d1cc7df',
project: '5d8fa6deefd05',
endpoint: 'https://localhost/v1',
key: '1589eb89e0c0153892c68867ea44137581a7a91390668ab1966a9c3a30a4d9ace58de90b3eaf61c0eae3f35e886b3d01cc8a674caf630c25a4428021ba0697cca5047b42bafb6710911e88fb1553d2833a221a94d2dc6fb55b7e500bc7873c4f09aab939e47aa959d55a972beacec8f7b86852b6842f4ca606908dea9d1cc7df',
};

// Init SDK
Expand All @@ -14,21 +15,34 @@ client
.setSelfSigned(true)
.setProject(config.project)
.setKey(config.key)
// .setJWT('jwt') // set this to authenticate using JWT
.setEndpoint(config.endpoint)
;
.setEndpoint(config.endpoint);

const collectionName = 'tasks';
const read = ['role:all'];
const write = ['role:all'];

const promise = database.createCollection(collectionName, read, write);

promise.then(function(response) {
console.log('success');
database.createBooleanAttribute(response.$id, 'completed', true, false, false);
database.createStringAttribute(response.$id, 'text', 255, true, '', false);
}, function(error) {
console.log('error', error.type, error.message);
});
// Create Collection
database.createCollection(collectionName, read, write)
.then(function(response) {
console.log('Collection created successfully');
// Create Boolean Attribute
database.createBooleanAttribute(response.$id, 'completed', true, false, false)
.then(function(booleanResponse) {
console.log('Boolean attribute created successfully');
})
.catch(function(error) {
console.error('Error creating boolean attribute', error);
});

// Create String Attribute
database.createStringAttribute(response.$id, 'text', 255, true, '', false)
.then(function(stringResponse) {
console.log('String attribute created successfully');
})
.catch(function(error) {
console.error('Error creating string attribute', error);
});
})
.catch(function(error) {
console.error('Error creating collection', error);
});