序列化:在列查询中使用函数

时间:2018-07-05 12:23:54

标签: node.js postgresql sequelize.js

我正在尝试编写以下SQL查询的顺序:

select * from properties where parse_input(address) LIKE parse_input('%some filter%')

其中parse_input是我在postgres DB中定义的函数。基本上,我想将相同的函数应用于过滤器和值,然后运行like比较。

我尝试了类似的操作:

Sequelize.where(Sequelize.fn('parse_input', Sequelize.col('address')), '$iLike', Sequelize.fn('parse_input', '%some filter%'))

我看到了生成的查询:

...AND "properties"."attribute" = parse_input("address") AND "properties"."comparator" = '$iLike' AND "properties"."logic" = '%some filter%';

但是出现errorMissingColumn错误。有提示吗?

1 个答案:

答案 0 :(得分:0)

找到解决方案:

import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or press Run > Flutter Hot Reload in IntelliJ). Notice that the
        // counter didn't reset back to zero; the application is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
   @override
Widget build(BuildContext context) {


  Widget gridSection = new Expanded(
    flex: 1,
    child: new GridView.count(
      crossAxisCount: 3,
      childAspectRatio: 1.0,
      shrinkWrap:true,
      mainAxisSpacing: 2.0,      
      crossAxisSpacing: 2.0,
      padding: const EdgeInsets.all(4.0),
      children: <String>[
            'http://www.for-example.org/img/main/forexamplelogo.png',
            'http://www.for-example.org/img/main/forexamplelogo.png',
            'http://www.for-example.org/img/main/forexamplelogo.png',
            'http://www.for-example.org/img/main/forexamplelogo.png',
            'http://www.for-example.org/img/main/forexamplelogo.png',
            'http://www.for-example.org/img/main/forexamplelogo.png',
            'http://www.for-example.org/img/main/forexamplelogo.png',
            'http://www.for-example.org/img/main/forexamplelogo.png',
            'http://www.for-example.org/img/main/forexamplelogo.png',
            'http://www.for-example.org/img/main/forexamplelogo.png',
            'http://www.for-example.org/img/main/forexamplelogo.png',
            'http://www.for-example.org/img/main/forexamplelogo.png',
            'http://www.for-example.org/img/main/forexamplelogo.png',
          ].map((String url) {
            return new GridTile(
                child: new Image.network(url, fit: BoxFit.cover));
          }).toList()),
  );

  Widget body = new Column(
    // This makes each child fill the full width of the screen
    crossAxisAlignment: CrossAxisAlignment.stretch,
    mainAxisSize: MainAxisSize.min,
    children: <Widget>[
      gridSection,
    ],
  );

  return new Scaffold(
    appBar: new AppBar(
      title: new Text("Example 2 Page"),
    ),
    body: new Padding(
      padding: new EdgeInsets.symmetric(vertical: 0.0, horizontal: 0.0),
      child: body,
    ),
  );
}

}