如何使用sails-filemaker查找一系列记录?

时间:2016-09-21 05:08:03

标签: sails.js filemaker

我在使用搜索条件或sails-filemaker的where条件时遇到问题。根据我在帆文件中读到的内容,我使用了正确的标准。我使用的工作是不使用find或where条件,并在查找后删除记录。好的,非常小的记录集,但它不优雅。

var staffCriteriaFind = {roleId:[1,2]} ;
var staffCriteriaWhere = {or:[{roleID:1},{roleId:2}]} ;

Staff.find().where().exec(function(error,staff){
    /* remove staff members who are not account managers or artists */
    for ( index = staff.length-1; index > 0; index--) {
        var staffMember = staff[index];
        if ( staffCriteriaFind.roleId.indexOf( staffMember.roleId ) == -1 ) {
            staff.splice([index],1) ;
        }
    }
    result.staff = staff ;
    return res.send(responseCode, result ) ;    
});

员工模型是

/**
* Staff.js
*
* @description :: Staff employed by the business
* @docs        :: http://sailsjs.org/#!documentation/models
*/

module.exports = {

    connection: 'filemaker',
    tableName: 'staff-list-api-layout',

    autoPK:false ,
    autoCreatedAt: false ,
    autoUpdatedAt: false ,

  attributes: {
        id: {
            columnName: 'staff_id_',
            type: 'integer',
            primaryKey: true,
            unique:true
        } , 
        role:{
            columnName:'staff_role::role',
            type: 'string'
        },
        timesheetSort:{
            columnName:'staff_role::timesheet_sort',
            type:'string'
        },
        roleId:{
            columnName: 'role_id',
            type: 'integer',
            foreignKey: true
        },
        name:{
            columnName:'full_name',
            type: 'string'
        },
        createdAt:{
            type:'date'
        },
        updatedAt:{
            type:'date'
        }
  }

};

如果我使用

var staffCriteriaFind = {roleId:[1,2]} ;
var staffCriteriaWhere = {or:[{roleID:1},{roleId:2}]} ;

Staff.find(staffCriteriaFind).where().exec(function(error,staff){
    result.staff = staff ;
    return res.send(responseCode, result ) ;    
});

我得到所有职员成员,其中roleId = 1,没有,其中roleId = 2。

如果我使用

var staffCriteriaFind = {roleId:[1,2]} ;
var staffCriteriaWhere = {or:[{roleID:1},{roleId:2}]} ;

Staff.find().where(staffCriteriaWhere).exec(function(error,staff){
    result.staff = staff ;
    return res.send(responseCode, result ) ;    
});

我根本没有员工记录......

在sails-filemaker中使用findCriteria或whereCriteria的正确方法是什么?需要搜索或搜索一系列值?

4 个答案:

答案 0 :(得分:1)

我最终使用了一个filemaker脚本,将参数传递给该脚本,然后解压缩了roleId,以便在filemaker中执行find。

var staffCriteria = {
                          'staff_id_' : '>0',
                          '-script' : 'find-staff-api-script',
                          '-script.param' : '{roleId:[1,2]}'
                    };
                    Staff.find(staffCriteria).where().exec(function(error,staff){

                        if ( error ) {
                            result.error = error ;
                            result.staffCriteria = staffCriteria ;
                        }
                        result.staff = staff ;
                        return res.send(responseCode, result ) ;    
                    });

有关更多示例,请参阅https://gist.github.com/toddgeist/13157485b81f3e2b985e

答案 1 :(得分:1)

经过多次搞乱后,我发现你可以使用Filemakers范围术语' ...'在查找功能中。



staff.find({ a_StaffID: '1...12', position: '100...400' })
.then('do whatever you need to do with the returned data')
.catch('do whatever you need to do with any error')




答案 2 :(得分:0)

Todd Geist是最好的人,但我可以尝试猜测

您的Staff.find可能使用FileMaker查找功能,因此它一次只能找到一个参数。尝试使用{roleId:[2,1]}代替,你可能会获得所有roleId = 1

问题是,我找不到find()。在sales-filemaker中的任何地方。我想你正在看newFindRequest(fmLayout,options.where),它是一个参数,而不是方法。

尝试staff.find(staffCriteriaWhere),这可能有效

答案 3 :(得分:0)

我的不好,哪里是sails方法,而不是sales-filemaker。

我想你应该试试这个:

Incident Identifier: D1567D74-C4CB-464D-945C-5510E22A5E67
CrashReporter Key:   45e776ed0586d581aba248bf3f23eaf42a231f2c
Hardware Model:      xxx
Process:             MyAppiOS [1576]
Path:                /private/var/containers/Bundle/Application/79C23898-D672-4AA6-BD4C-6EBAE68918FF/xxxxxx.app/xxxxxxiOS
Identifier:          it.xxxxx.xxxxxx
Version:             1.3 (1.3)
Code Type:           ARM-64 (Native)
Parent Process:      launchd [1]

Date/Time:           2016-07-31 13:37:27.27 -0700
Launch Time:         2016-07-31 13:37:27.27 -0700
OS Version:          iOS 9.3.3 (13G34)
Report Version:      105

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Filtered syslog:
None found

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x000000018071c11c 0x180700000 + 114972
1   libsystem_pthread.dylib         0x00000001807e8ef8 0x1807e4000 + 20216
2   libsystem_c.dylib               0x000000018068ddc8 0x18062c000 + 400840
3   MyAppiOS                    0x0000000100ef7b0c 0x10007c000 + 15186700
4   libsystem_platform.dylib        0x00000001807e194c 0x1807dc000 + 22860
5   libsystem_pthread.dylib         0x00000001807e8ef8 0x1807e4000 + 20216
6   libsystem_c.dylib               0x000000018068ddc8 0x18062c000 + 400840
7   MyAppiOS                    0x0000000100fe8988 0x10007c000 + 16173448
8   MyAppiOS                    0x0000000100ef805c 0x10007c000 + 15188060
9   MyAppiOS                    0x0000000100ef7518 0x10007c000 + 15185176
10  MyAppiOS                    0x0000000100ef6354 0x10007c000 + 15180628
11  MyAppiOS                    0x0000000100eef2d0 0x10007c000 + 15151824
12  MyAppiOS                    0x000000010045d178 0x10007c000 + 4067704
13  MyAppiOS                    0x000000010054cf44 0x10007c000 + 5050180
14  MyAppiOS                    0x000000010054c998 0x10007c000 + 5048728
15  MyAppiOS                    0x0000000100a58094 0x10007c000 + 10338452
16  MyAppiOS                    0x000000010095fd8c 0x10007c000 + 9321868
17  MyAppiOS                    0x000000010095f57c 0x10007c000 + 9319804
18  MyAppiOS                    0x00000001002a9cf4 0x10007c000 + 2284788
19  MyAppiOS                    0x000000010043d364 0x10007c000 + 3937124
20  MyAppiOS                    0x0000000100f06bf4 0x10007c000 + 15248372
21  MyAppiOS                    0x0000000100f6a974 0x10007c000 + 15657332
22  MyAppiOS                    0x0000000100eb0c34 0x10007c000 + 14896180
23  MyAppiOS                    0x0000000100eb406c 0x10007c000 + 14909548
24  UIKit                           0x0000000185d4e9c0 0x185cc4000 + 567744
25  UIKit                           0x0000000185f7e184 0x185cc4000 + 2859396
26  UIKit                           0x0000000185f825f0 0x185cc4000 + 2876912
27  UIKit                           0x0000000185f7f764 0x185cc4000 + 2864996
28  FrontBoardServices              0x00000001825237ac 0x1824fc000 + 161708
29  FrontBoardServices              0x0000000182523618 0x1824fc000 + 161304
30  FrontBoardServices              0x00000001825239c8 0x1824fc000 + 162248
31  CoreFoundation                  0x0000000180b3909c 0x180a58000 + 921756
32  CoreFoundation                  0x0000000180b38b30 0x180a58000 + 920368
33  CoreFoundation                  0x0000000180b36830 0x180a58000 + 911408
34  CoreFoundation                  0x0000000180a60c50 0x180a58000 + 35920
35  UIKit                           0x0000000185d4794c 0x185cc4000 + 538956
36  UIKit                           0x0000000185d42088 0x185cc4000 + 516232
37  MyAppiOS                    0x00000001002e48fc 0x10007c000 + 2525436
38  MyAppiOS                    0x000000010031bc8c 0x10007c000 + 2751628
39  MyAppiOS                    0x00000001002a9c28 0x10007c000 + 2284584
40  MyAppiOS                    0x000000010043d364 0x10007c000 + 3937124
41  MyAppiOS                    0x0000000100f06bf4 0x10007c000 + 15248372
42  MyAppiOS                    0x0000000100f6a974 0x10007c000 + 15657332
43  MyAppiOS                    0x0000000100f6f1fc 0x10007c000 + 15675900
44  MyAppiOS                    0x0000000100ffa6f4 0x10007c000 + 16246516
45  MyAppiOS                    0x0000000100ec5050 0x10007c000 + 14979152
46  libdyld.dylib                   0x00000001805fe8b8 0x1805fc000 + 10424

Thread 1:
0   libsystem_kernel.dylib          0x000000018071cb48 0x180700000 + 117576
1   libsystem_pthread.dylib         0x00000001807e5530 0x1807e4000 + 5424
2   libsystem_pthread.dylib         0x00000001807e5020 0x1807e4000 + 4128

Thread 2 name:  Dispatch queue: com.apple.libdispatch-manager
Thread 2:
0   libsystem_kernel.dylib          0x000000018071d4d8 0x180700000 + 120024
1   libdispatch.dylib               0x00000001805e07d8 0x1805cc000 + 83928
2   libdispatch.dylib               0x00000001805cf648 0x1805cc000 + 13896

Thread 3:
0   libsystem_kernel.dylib          0x000000018071cb48 0x180700000 + 117576
1   libsystem_pthread.dylib         0x00000001807e5530 0x1807e4000 + 5424
2   libsystem_pthread.dylib         0x00000001807e5020 0x1807e4000 + 4128

Thread 4:
0   libsystem_kernel.dylib          0x000000018071c41c 0x180700000 + 115740
1   libsystem_c.dylib               0x000000018063922c 0x18062c000 + 53804
2   libc++.1.dylib                  0x00000001801b13b4 0x18016c000 + 283572
3   JavaScriptCore                  0x000000018477a698 0x1841f8000 + 5777048
4   JavaScriptCore                  0x000000018477a348 0x1841f8000 + 5776200
5   JavaScriptCore                  0x000000018477cae0 0x1841f8000 + 5786336
6   JavaScriptCore                  0x000000018477ca70 0x1841f8000 + 5786224
7   libsystem_pthread.dylib         0x00000001807e7b28 0x1807e4000 + 15144
8   libsystem_pthread.dylib         0x00000001807e7a8c 0x1807e4000 + 14988
9   libsystem_pthread.dylib         0x00000001807e5028 0x1807e4000 + 4136

Thread 5 name:  WebThread
Thread 5:
0   libsystem_kernel.dylib          0x0000000180700fd8 0x180700000 + 4056
1   libsystem_kernel.dylib          0x0000000180700e54 0x180700000 + 3668
2   CoreFoundation                  0x0000000180b38c60 0x180a58000 + 920672
3   CoreFoundation                  0x0000000180b36964 0x180a58000 + 911716
4   CoreFoundation                  0x0000000180a60c50 0x180a58000 + 35920
5   WebCore                         0x0000000184a46108 0x1849d0000 + 483592
6   libsystem_pthread.dylib         0x00000001807e7b28 0x1807e4000 + 15144
7   libsystem_pthread.dylib         0x00000001807e7a8c 0x1807e4000 + 14988
8   libsystem_pthread.dylib         0x00000001807e5028 0x1807e4000 + 4136

Thread 6:
0   libsystem_kernel.dylib          0x0000000180701014 0x180700000 + 4116
1   MyAppiOS                    0x0000000100fd4784 0x10007c000 + 16091012
2   MyAppiOS                    0x0000000100f34c20 0x10007c000 + 15436832
3   MyAppiOS                    0x0000000100fb62dc 0x10007c000 + 15966940
4   MyAppiOS                    0x0000000100fd517c 0x10007c000 + 16093564
5   libsystem_pthread.dylib         0x00000001807e7b28 0x1807e4000 + 15144
6   libsystem_pthread.dylib         0x00000001807e7a8c 0x1807e4000 + 14988
7   libsystem_pthread.dylib         0x00000001807e5028 0x1807e4000 + 4136

Thread 7:
0   libsystem_kernel.dylib          0x000000018071cb48 0x180700000 + 117576
1   libsystem_pthread.dylib         0x00000001807e5530 0x1807e4000 + 5424
2   libsystem_pthread.dylib         0x00000001807e5020 0x1807e4000 + 4128

Thread 8:
0   libsystem_kernel.dylib          0x000000018071bf24 0x180700000 + 114468
1   libsystem_pthread.dylib         0x00000001807e6ce8 0x1807e4000 + 11496
2   MyAppiOS                    0x0000000100fbadc0 0x10007c000 + 15986112
3   MyAppiOS                    0x0000000100fc69c4 0x10007c000 + 16034244
4   MyAppiOS                    0x0000000100fb1d98 0x10007c000 + 15949208
5   MyAppiOS                    0x00000001003e9910 0x10007c000 + 3594512
6   MyAppiOS                    0x000000010054c7e4 0x10007c000 + 5048292
7   MyAppiOS                    0x000000010054c88c 0x10007c000 + 5048460
8   MyAppiOS                    0x000000010054c13c 0x10007c000 + 5046588
9   MyAppiOS                    0x000000010054ab78 0x10007c000 + 5041016
10  MyAppiOS                    0x000000010043d364 0x10007c000 + 3937124
11  MyAppiOS                    0x0000000100f06bf4 0x10007c000 + 15248372
12  MyAppiOS                    0x0000000100f6a974 0x10007c000 + 15657332
13  MyAppiOS                    0x0000000100fb6344 0x10007c000 + 15967044
14  MyAppiOS                    0x0000000100fd517c 0x10007c000 + 16093564
15  libsystem_pthread.dylib         0x00000001807e7b28 0x1807e4000 + 15144
16  libsystem_pthread.dylib         0x00000001807e7a8c 0x1807e4000 + 14988
17  libsystem_pthread.dylib         0x00000001807e5028 0x1807e4000 + 4136

Thread 9:
0   libsystem_kernel.dylib          0x000000018071bf24 0x180700000 + 114468
1   libsystem_pthread.dylib         0x00000001807e6ce8 0x1807e4000 + 11496
2   MyAppiOS                    0x0000000100fbadc0 0x10007c000 + 15986112
3   MyAppiOS                    0x0000000100fc69c4 0x10007c000 + 16034244
4   MyAppiOS                    0x0000000100f621f4 0x10007c000 + 15622644
5   MyAppiOS                    0x00000001003e8318 0x10007c000 + 3588888
6   MyAppiOS                    0x000000010054a3dc 0x10007c000 + 5039068
7   MyAppiOS                    0x00000001003b5698 0x10007c000 + 3380888
8   MyAppiOS                    0x00000001003b5460 0x10007c000 + 3380320
9   MyAppiOS                    0x0000000100601e80 0x10007c000 + 5791360
10  MyAppiOS                    0x0000000100601d18 0x10007c000 + 5791000
11  MyAppiOS                    0x0000000100601c3c 0x10007c000 + 5790780
12  MyAppiOS                    0x0000000100e60788 0x10007c000 + 14567304
13  MyAppiOS                    0x000000010054ab78 0x10007c000 + 5041016
14  MyAppiOS                    0x000000010043d364 0x10007c000 + 3937124
15  MyAppiOS                    0x0000000100f06bf4 0x10007c000 + 15248372
16  MyAppiOS                    0x0000000100f6a974 0x10007c000 + 15657332
17  MyAppiOS                    0x0000000100fb6344 0x10007c000 + 15967044
18  MyAppiOS                    0x0000000100fd517c 0x10007c000 + 16093564
19  libsystem_pthread.dylib         0x00000001807e7b28 0x1807e4000 + 15144
20  libsystem_pthread.dylib         0x00000001807e7a8c 0x1807e4000 + 14988
21  libsystem_pthread.dylib         0x00000001807e5028 0x1807e4000 + 4136

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000000   x1: 0x0000000000000000   x2: 0x0000000000000000   x3: 0x0000000180748664
    x4: 0x0000000000000043   x5: 0x0000000000000041   x6: 0x0000000000000000   x7: 0x0000000000000fa0
    x8: 0x0000000008000000   x9: 0x0000000004000000  x10: 0x0000000136790000  x11: 0x0000000000003fff
   x12: 0x000000013678c000  x13: 0x0000000000003fff  x14: 0xffffffffffffc000  x15: 0x0000000000003fff
   x16: 0x0000000000000148  x17: 0x0000000000000000  x18: 0x0000000000000000  x19: 0x0000000000000006
   x20: 0x000000019ede5000  x21: 0x0000000101489d45  x22: 0x0000000101489e0c  x23: 0x4900c357811c5df7
   x24: 0x000000016fd7fd28  x25: 0x0000000101489dbf  x26: 0x0000000137916b60  x27: 0x0000000000000001
   x28: 0x000000013683ae00  fp: 0x000000016fd7fcc0   lr: 0x00000001807e8ef8
    sp: 0x000000016fd7fca0   pc: 0x000000018071c11c cpsr: 0x00000000

Staff.find().where({roleId:1 },{roleId:2 })