linvodb3 icon indicating copy to clipboard operation
linvodb3 copied to clipboard

Regex Type not working

Open geblanco opened this issue 8 years ago • 1 comments

Hello,

I have schema with two regex type fields, but I cannot get them to work as expected. None of them initializes to default and I am not able to save/update them either. Here is my schema and some sample code:

'use strict';

var LinvoDB = require('linvodb3')
LinvoDB.dbPath = '/valid/path/here'

var schema = {
    name: { type: String, index: true, unique: true },
    text: { type: String, default: '' },
    exec: { type: String, default: '' },
    icon: { type: String, default: '' },
    data: { type: String, default: '_no_data_' },
    type: { type: String, default: '_system_' },
    regex0: { type: RegExp, default: new RegExp() },
    regex1: { type: RegExp, default: new RegExp() }
}

var AppSchema = new LinvoDB('apps', schema, {})

var data = [new AppSchema({
    name: 'Google Search',
    text: 'Search whatever on the net',
    exec: 'netSearch',
    icon: 'google.png',
    type: '_system_',
}), new AppSchema({
    name: 'Github',
    text: 'Search whatever on Github',
    exec: 'githubSearch',
    data: 'https://www.github.com/search?q=',
    icon: 'github.png',
    type: '_web_app_',
    regex0: new RegExp('^github (.*)', 'i')
})]


AppSchema.save( data, ( err ) => {
    console.log( err ) // logs null
})

AppSchema.findOne({ exec: 'netSearch' }, ( err, doc ) => {
    console.log(doc.data) // logs '_no_data_'
    console.log(doc.regex0) // logs undefined
})

AppSchema.findOne({ exec: 'githubSearch' }, ( err, doc ) => {
    console.log(doc.regex0) // logs undefined
    console.log(doc.regex1) // logs undefined
    doc.regex1 = new RegExp('^git (.*)', 'i');
    doc.save(( err, newDoc ) => {
        console.log(newDoc.regex1) // logs undefined
    })
})

geblanco avatar Jun 03 '16 16:06 geblanco

I added the ability to save regex (serialize/deserialize), but not sure if validation would work though

Ivshti avatar Jun 03 '16 22:06 Ivshti