strapi/docs/.vuepress/dist/assets/js/17.1c93d494.js

1 line
69 KiB
JavaScript
Raw Normal View History

2018-10-05 17:24:17 +02:00
(window.webpackJsonp=window.webpackJsonp||[]).push([[17],{222:function(t,a,s){"use strict";s.r(a);var n=s(0),e=Object(n.a)({},function(){this.$createElement;this._self._c;return this._m(0)},[function(){var t=this,a=t.$createElement,s=t._self._c||a;return s("div",{staticClass:"content"},[s("h1",{attrs:{id:"query-interface"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#query-interface","aria-hidden":"true"}},[t._v("#")]),t._v(" Query Interface")]),t._v(" "),s("p",[t._v("The Waterline Query Interface allows you to interact with your models the same\nway no matter which adapter they are using. This means you can use the same Query\nLanguage whether your data lives in MySQL, MongoDB, PostgreSQL, etc.")]),t._v(" "),s("h2",{attrs:{id:"query-methods"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#query-methods","aria-hidden":"true"}},[t._v("#")]),t._v(" Query Methods")]),t._v(" "),s("p",[t._v("Every model in Waterline will have a set of query methods exposed on it to allow\nyou to interact with the database in a normalized fashion.\nThese are known as the CRUD ("),s("code",[t._v("Create")]),t._v(", "),s("code",[t._v("Read")]),t._v(", "),s("code",[t._v("Update")]),t._v(" and "),s("code",[t._v("Delete")]),t._v(") methods and\nis the primary way of interacting with your data.")]),t._v(" "),s("p",[t._v("There are also a special set of queries known as "),s("em",[t._v("dynamic queries")]),t._v(".\nThese are special class methods that are dynamically generated when you initialize Waterline.\nWe call them dynamic finders. They perform many of the same functions as the other class\nmethods but you can call them directly on an attribute in your model.")]),t._v(" "),s("p",[t._v("For most class methods, the callback parameter is optional and if one is not supplied,\nit will return a chainable object.")]),t._v(" "),s("h3",{attrs:{id:"find-criteria-callback"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#find-criteria-callback","aria-hidden":"true"}},[t._v("#")]),t._v(" .find(criteria, [callback])")]),t._v(" "),s("p",[s("code",[t._v("find")]),t._v(" will return an array of records that match the supplied criteria.\nCriteria can be built using the Query Language.")]),t._v(" "),s("ul",[s("li",[t._v("The "),s("code",[t._v("criteria")]),t._v(" is required and accepts "),s("code",[t._v("{}")]),t._v(", "),s("code",[t._v("[{}]")]),t._v(", "),s("code",[t._v("string")]),t._v(" and "),s("code",[t._v("int")]),t._v(" data types.")]),t._v(" "),s("li",[t._v("The "),s("code",[t._v("callback")]),t._v(" function is optional.")])]),t._v(" "),s("p",[t._v("Any string arguments passed must be the ID of the record.\nThis method will always return records in an array.\nIf you are trying to find an attribute that is an array, you must wrap it in an additional\nset of brackets otherwise Waterline will think you want to perform an "),s("code",[t._v("inQuery")]),t._v(".")]),t._v(" "),s("div",{staticClass:"language-js extra-class"},[s("pre",{pre:!0,attrs:{class:"language-js"}},[s("code",[t._v("User"),s("span",{attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{attrs:{class:"token function"}},[t._v("find")]),s("span",{attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n name"),s("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{attrs:{class:"token string"}},[t._v("'Walter Jr'")]),t._v("\n "),s("span",{attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{attrs:{class:"token function"}},[t._v("exec")]),s("span",{attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" users"),s("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{attrs:{cl