Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

changed the title

  • Loading branch information...
commit b38f0e49d683e0f422a696bf341dfaaf8e05d965 1 parent 5d48bea
foxbunny authored anandology committed
Showing with 28 additions and 28 deletions.
  1. +28 −28 cookbook/where_dict.md
View
56 cookbook/where_dict.md
@@ -1,33 +1,33 @@
---
layout: default
-title: Using dict as where clause
+title: Using a dictionary as where clause
---
-# Using dict as where clause
-
-Problem
--------
-
-You want to create a dictionary of where clauses dynamically and use it in a query.
-
-Solution
---------
-
- >>> import web
- >>> db = web.database(dbn='postgres', db='mydb', user='postgres')
- >>> where_dict = {'col1': 1, col2: 'sometext'}
- >>> db.delete('mytable', where=web.db.sqlwhere(where_dict), _test=True)
- <sql: "DELETE FROM mytable WHERE col1 = 1 AND col2 = 'sometext'">
-
-
-
-Explanation
------------
-
-`web.db.sqlwhere` takes a Python dictionary as an argument and converts it into a string useful for where clause in different queries. You can also use an optional `grouping` argument to define the exact gouping of the individual keys. For instance:
-
- >>> import web
- >>> web.db.sqlwhere({'a': 1, 'b': 2}, grouping=' OR ')
- 'a = 1 OR b = 2'
-
+# Using a dictionary as where clause
+
+Problem
+-------
+
+You want to create a dictionary of where clauses dynamically and use it in a query.
+
+Solution
+--------
+
+ >>> import web
+ >>> db = web.database(dbn='postgres', db='mydb', user='postgres')
+ >>> where_dict = {'col1': 1, col2: 'sometext'}
+ >>> db.delete('mytable', where=web.db.sqlwhere(where_dict), _test=True)
+ <sql: "DELETE FROM mytable WHERE col1 = 1 AND col2 = 'sometext'">
+
+
+
+Explanation
+-----------
+
+`web.db.sqlwhere` takes a Python dictionary as an argument and converts it into a string useful for where clause in different queries. You can also use an optional `grouping` argument to define the exact gouping of the individual keys. For instance:
+
+ >>> import web
+ >>> web.db.sqlwhere({'a': 1, 'b': 2}, grouping=' OR ')
+ 'a = 1 OR b = 2'
+
Default for `grouping` is `' AND '`.
Please sign in to comment.
Something went wrong with that request. Please try again.