Gravity
Search…
Gravity
Welcome to Gravity
Getting Started
Stack
Updates
Changelog
Gravity Server
Introduction
Installation
Application Structure
REST API
Authentication
Config
Environment Variables
Database Queries
Handling Errors
Logging
Push Notifications
Email Notifications
User Feedback
Permissions (Roles)
File Uploads
Payments
Free Accounts
CLI Toolbelt
Testing
Gravity Web
Introduction
Tailwind & SCSS
Routing
Events
Authentication
Hooks
Views
Handling Errors
Deployment
Components
Gravity Native
Introduction
Prerequisites
Installation
App Context
Authentication
Magic Links
Handling Errors
Navigation
Config
Events
Views
Components
Push Notifications
Payments
Building Your App
Mission Control
Introduction
Installation
User Management
Feedback
Events
Logs
Powered By
GitBook
Database Queries
Before making a database query in your application, you must import the database model into the file where your methods are contained.
1
// sql
2
const
db
=
require
(
'./knex'
)();
3
​
4
// mongo
5
const
mongoose
=
require
(
'mongoose'
);
Copied!
Performing Database Queries
You can perform a query using
Knex
or
Mongoose
.
1
// knex
2
return
await
db
(
'user'
).
select
(
'*'
).
where
({
account_id
:
account
});
3
​
4
// mongoose
5
return
await
User
.
findOne
({
account_id
:
account
});
Copied!
Gravity Server - Previous
Environment Variables
Next - Gravity Server
Handling Errors
Last modified
1yr ago
Copy link
Contents
Performing Database Queries