DB Query
With DB Query, you can write database queries to directly modify or manipulate database information. For simple query operations, DB Query can be used to easily create and use APIs. This section explains how to use DB Query.
You need to set up a Connection before you can use DB Query.
Using Variables
In your queries, you can use values passed as parameters. Here's how:
// Variables are encapsulated with ${}.
SELECT * FROM users WHERE id=${id} AND name=${data.name}
If the data type of the variable is an Object, you can retrieve the value in the format of data.name. N-depth format is also possible. Example) data.users.id
Query
In WEVY, you need to create various queries depending on the type of database. Below is the query usage according to the database type.
MYSQL, POSTGRE, MARIADB
Use the standard SQL query statements.
SELECT * FROM users WHERE id=${id} AND name=${data.name}
MongoDB
MongoDB provides a unique JSON format query object that allows for the execution of MongoDB's CRUD operations. Below is the basic format of the query object:
{
"collection": "collectionName",
"type": "operationType",
"data": {},
"where": {},
"sort": {},
"limit": 0
}
- collection: The name of the MongoDB collection on which the operation will be performed. (Required)
- type: The type of operation to be performed. (One of find, insertMany, insert, delete, update)
- data: A data object or array of objects used for insert and update operations.
- where: An object specifying conditions for the find, delete, and update operations.
- sort: An object used to sort the results of a find operation.
- limit: A number used to limit the number of results of a find operation.
Query Examples
Finding documents with specific conditions:
{
"collection": "myCollection",
"type": "find",
"where": {
"status": "d"
}
}
Insert multiple documents:
{
"collection": "myCollection",
"type": "insertMany",
"data": [
{ "name": "John", "age": 30 },
{ "name": "Jane", "age": 25 }
]
}
Insert a single document:
{
"collection": "myCollection",
"type": "insert",
"data": { "name": "Doe", "age": 40 }
}
Delete documents that match a condition:
{
"collection": "myCollection",
"type": "delete",
"where": { "age": { "$gt": 35 } }
}
Update a document:
{
"collection": "myCollection",
"type": "update",
"where": { "name": "Doe" },
"data": { "age": 42 }
}