当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ModelManager.create方法代码示例

本文整理汇总了TypeScript中rev-models.ModelManager.create方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ModelManager.create方法的具体用法?TypeScript ModelManager.create怎么用?TypeScript ModelManager.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rev-models.ModelManager的用法示例。


在下文中一共展示了ModelManager.create方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: Post

(async () => {

    // Create some data

    await modelManager.create(new Post({
        title: 'My First Post',
        body: 'This is a really cool post made in RevJS',
        status: 'draft'
    }));

    await modelManager.create(new Post({
        title: 'RevJS is awesome!',
        body: 'I should use it for ALL TEH THINGZZZ!',
        status: 'published'
    }));

    // Read it back

    const res = await modelManager.read(Post, {
        where: {
            _or: [
                { title: { _like: '%RevJS%' }},
                { body: { _like: '%RevJS%' }}
            ]
        }
    });

    console.log(res.results);

})();
开发者ID:RevFramework,项目名称:rev-framework,代码行数:30,代码来源:creating_and_reading_a_model.ts

示例2: beforeEach

        beforeEach(async () => {
            modelManager = models.getModelManager();
            apiManager = new ModelApiManager(modelManager);
            apiManager.register(models.Post, { operations: ['read', 'update'] });
            apiManager.register(models.User, { operations: ['read'] });
            apiManager.register(models.Comment, { operations: ['read'] });
            api = new GraphQLApi(apiManager);
            schema = api.getSchema();

            existingPost = new models.Post({
                id: 10,
                title: 'Existing Post',
                body: 'This post has already been created',
                published: true,
                post_date: '2017-12-23T09:30:21'
            });
            existingPost2 = new models.Post({
                id: 11,
                title: 'Another Post',
                body: 'This is another post',
                published: true,
                post_date: '2018-01-05T12:23:34'
            });
            await modelManager.create(existingPost);
            await modelManager.create(existingPost2);
        });
开发者ID:RevFramework,项目名称:rev-framework,代码行数:26,代码来源:update.tests.ts

示例3: MongoDBBackend

(async () => {

    // Create a MongoDBBackend and connect to MongoDB

    const mongo = new MongoDBBackend({
        url: 'mongodb://localhost:27017',
        dbName: 'example_db'
    });
    await mongo.connect();

    // Create a ModelManager, and assign MongoDB as the default backend

    const modelManager = new ModelManager();
    modelManager.registerBackend('default', mongo);
    modelManager.register(TestModel);

    // Create some data, then disconnect afterwards

    await modelManager.create(new TestModel({
        name: 'data from RevJS!',
        description: 'This beautiful record was created by RevJS',
        score: 110
    }));
    console.log('Data successfully created in MongoDB!');

    await mongo.disconnect();

})();
开发者ID:RevFramework,项目名称:rev-framework,代码行数:28,代码来源:using_a_mongodb_backend.ts

示例4: beforeEach

        beforeEach(async () => {
            modelManager = models.getModelManager();
            apiManager = new ModelApiManager(modelManager);
            apiManager.register(models.ModelWithAllScalarFields, { operations: ['read'] });
            api = new GraphQLApi(apiManager);
            api.fieldMappings.forEach((converter) => {
                if (converter[0] == fields.TextFieldBase) {
                    converter[1].converter = (model, fieldName) => {
                        return 'I am a custom converter!';
                    };
                }
            });

            data = new models.ModelWithAllScalarFields({
                integerField: 2,
                numberField: 3.456,
                textField: 'I should be overridden...',
                emailField: 'test@test.com',
                urlField: 'http://www.test.com',
                passwordField: 'password123',
                booleanField: true,
                selectField: 'Y',
                multiSelectField: ['A', 'B'],
                dateField: '2017-12-25',
                timeField: '12:13:14',
                dateTimeField: '2017-12-25T12:13:14'
            });
            await modelManager.create(data);

            schema = api.getSchema();
        });
开发者ID:RevFramework,项目名称:rev-framework,代码行数:31,代码来源:reading_scalar_data.tests.ts

示例5: createData

export async function createData() {

    await modelManager.create(new Post({
        category: 'agriculture',
        title: 'My First Post',
        body: 'This is a really cool post made in RevJS',
        rating: 3,
        published: true
    }));

    await modelManager.create(new Post({
        category: 'technology',
        title: 'RevJS is awesome!',
        body: 'I should use it for ALL TEH THINGZZZ!',
        rating: 5,
        published: true
    }));

    await modelManager.create(new Post({
        category: 'technology',
        title: 'Draft Post',
        body: 'Not ready to publish this just yet...',
        published: false
    }));

    await modelManager.create(new Post({
        category: 'science',
        title: 'Another Draft Post',
        body: 'This post sucks, so will not be published yet!',
        published: false
    }));

    await modelManager.create(new Post({
        category: 'science',
        title: 'Cool as post',
        body: 'Read this post, its great!...',
        rating: 5,
        published: true
    }));

    await modelManager.create(new Post({
        category: 'music',
        title: 'New release from Fiddy Cent',
        body: 'Its called "Ok, I admit it, I suck" :)',
        rating: 2,
        published: true
    }));

    await modelManager.create(new Post({
        category: 'music',
        title: 'New release from Bruno Mars',
        body: 'Its called "Daaaamn, you ugly"',
        rating: 2,
        published: true
    }));

}
开发者ID:RevFramework,项目名称:rev-framework,代码行数:57,代码来源:models.ts

示例6: createData

export async function createData(manager: ModelManager): Promise<IModelTestData> {

    for (const user of users) {
        try {
            await manager.create(user);
        }
        catch (e) {
            console.log(user);
            console.log(e.result.validation.fieldErrors);
        }
    }

    for (const post of posts) {
        try {
            await manager.create(post);
        }
        catch (e) {
            console.log(post);
            console.log(e.result.validation.fieldErrors);
        }
    }

    for (const comment of comments) {
        try {
            await manager.create(comment);
        }
        catch (e) {
            console.log(comment);
            console.log(e.result.validation.fieldErrors);
        }
    }

    return {
        users,
        posts,
        comments
    };

}
开发者ID:RevFramework,项目名称:rev-framework,代码行数:39,代码来源:modeldata.ts

示例7: Post

(async () => {
    try {

        // Create a valid post
        await modelManager.create(new Post({
            title: 'This is a valid post',
            body: 'No alternative facts here!',
            is_published: true
        }));

        // Try to create a duplicate post...
        await modelManager.create(new Post({
            title: 'This is a valid post',
            body: 'Not really! Its a duplicate, so should cause an error...',
            is_published: true
        }));

    }
    catch (e) {
        console.error(e.message);
    }
})();
开发者ID:RevFramework,项目名称:rev-framework,代码行数:22,代码来源:custom_validation.ts

示例8: Comment

(async () => {

    try {
        await modelManager.create(new Comment({
            comment: 'This comment has an invalid status',
            status: 'Awesome!'
        }));
    }
    catch (e) {
        if (e instanceof ValidationError) {
            console.log('Model Failed Validation :(');
            console.log('Field Errors:', e.validation.fieldErrors);
            console.log('Model Errors:', e.validation.modelErrors);
        }
        else {
            throw e;
        }
    }

})();
开发者ID:RevFramework,项目名称:rev-framework,代码行数:20,代码来源:handling_validation_errors.ts

示例9: getData

export async function getData(manager: ModelManager): Promise<IModelTestData> {

    const posts = [
        new Post({
            id: 1,
            title: 'RevJS v1.0.0 Released!',
            body: `Great news! RevJS has finally hit version 1!

Go download it now and use it for ALL TEH THINGS!`,
            published: false,
            post_date: '2018-01-31T12:11:10',
        }),
        new Post({
            id: 2,
            title: 'JavaScript is Awesome',
            body: `One language to rule them all...

My precious...`,
            keywords: 'js, javascript, awesome',
            published: true,
            post_date: '2017-04-15T13:14:15',
        }),
        new Post({
            id: 3,
            title: 'Ruby Sucks',
            body: `Why do people use it?
... who knows!`,
            keywords: 'ruby, sucks',
            published: true,
            post_date: '2017-07-02T01:02:03',
        }),
        new Post({
            id: 4,
            title: 'Post 4',
            body: `Another post...`,
            published: true,
            post_date: '2017-04-15T13:14:15',
        }),
        new Post({
            id: 5,
            title: 'Post 5',
            body: `Another post...`,
            published: true,
            post_date: '2017-04-15T13:14:15',
        }),
        new Post({
            id: 6,
            title: 'Post 6',
            body: `Another post...`,
            published: true,
            post_date: '2017-04-15T13:14:15',
        }),
        new Post({
            id: 7,
            title: 'Post 7',
            body: `Another post...`,
            published: true,
            post_date: '2017-04-15T13:14:15',
        })
    ];

    for (const post of posts) {
        try {
            await manager.create(post);
        }
        catch (e) {
            console.log(post);
            console.log(e.result.validation.fieldErrors);
        }
    }

    return {
        posts
    };

}
开发者ID:RevFramework,项目名称:rev-framework,代码行数:76,代码来源:modeldata.ts


注:本文中的rev-models.ModelManager.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。