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

can't manipulate the data in postgres #1

Open
lrAlval opened this issue Aug 20, 2015 · 1 comment
Open

can't manipulate the data in postgres #1

lrAlval opened this issue Aug 20, 2015 · 1 comment

Comments

@lrAlval
Copy link

lrAlval commented Aug 20, 2015

This is My JS Code

tasks = new SQL.Collection("tasks");

if (Meteor.isClient) {

    tasks.createTable({
        id: ['$number'],
        text: ['$string'],
        checked: ['$bool', {$default: false}],
        createdAt: ['$datetime']
    });


    Template.body.helpers({
        tasks: function () {
            return tasks.select().fetch();
        }
    });

    Template.body.events({
        "submit .new-task": function (event) {
            event.preventDefault();
            var text = event.target.text.value;
            tasks.insert({
                text: text,
                createdAt: new Date()
            }).save();
            event.target.text.value = "";
        }
    });


    Template.task.events({
        "click .toggle-checked": function () {
            tasks.update({
                id: this._id,
                "checked": !this.checked
            }).where("id = ?", this.id).save();
        },
        "click .delete": function () {
            tasks.remove().where("id = ?", this.id).save();
        }
    });
}

if (Meteor.isServer) {
    tasks.createTable({
        id: ['$number'],
        text: ['$string'],
        checked: ['$bool', {$default: false}],
        createdAt: ['$datetime']
    }).save();

    tasks.publish('Tasks', function () {
        return tasks.select().save();
    })
}

this is my html Code

<head>
    <title>Todo List</title>
</head>

<body>
<div class="container">
    <header>
        <h1>Todo List</h1>

        <form class="new-task">
            <input type="text" name="text" placeholder="Type to add new tasks" />
        </form>
    </header>

    <ul>
        {{#each tasks}}
            {{> task}}
        {{/each}}
    </ul>
</div>
</body>

<template name="task">
    <li class="{{#if checked}}checked{{/if}}">
        <button class="delete">&times;</button>

        <input type="checkbox" checked="{{checked}}" class="toggle-checked"/>

        <span class="text">{{text}}</span>
    </li>
</template>

and this is the error log :

TypeError: Cannot call method 'query' of null

please help me i cant find the mistake;

thanks in
advance

@MichaelHirn
Copy link
Member

Hi @lrAlval . I think the problem emerges from these lines, that get executed on the server.

tasks.createTable({
        id: ['$number'],
        text: ['$string'],
        checked: ['$bool', {$default: false}],
        createdAt: ['$datetime']
    }).save();

No need to call .save() when creating a table. You can do just the same as you do on the client. Let me know if this fixed the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants