You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/06-concepts/06-database/01-connection.md
+2-4Lines changed: 2 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,6 @@ In Serverpod the connection details and password for the database are stored ins
4
4
5
5
The easiest way to get started is to use a Docker container to run your local Postgres server, and this is how Serverpod is set up out of the box. This page contains more detailed information if you want to connect to another database instance or run Postgres locally yourself.
6
6
7
-
8
7
### Connection details
9
8
10
9
Each environment configuration contains a `database` keyword that specifies the connection details.
@@ -49,7 +48,6 @@ database:
49
48
50
49
In this example, Postgres will look for tables in the `custom` schema first, and then fall back to `public` if needed. This gives you more control over where your data lives and how it’s accessed
51
50
52
-
53
51
### Database password
54
52
55
53
The database password is stored in a separate file called `passwords.yaml` in the same `config` directory. The password for each environment is stored under the `database` keyword in the file.
@@ -102,7 +100,6 @@ To connect to a remote Postgres server (that you have installed on a VPS or VDS)
102
100
- You may need to open the database port on the machine. This may include configuring its firewall.
103
101
- Update your Serverpod `database` config to use the public network address, database name, port, user, and password.
104
102
105
-
106
103
### Connecting to Google Cloud SQL
107
104
108
105
You can connect to a Google Cloud SQL Postgres instance in two ways:
@@ -114,13 +111,14 @@ The next step is to update the database password in `passwords.yaml` and the con
114
111
115
112
:::info
116
113
117
-
If you are using the `isUnixSocket` don't forget to add **"/.s.PGSQL.5432"** to the end of the `host` IP address. Otherwise, your Google Cloud Run instance will not be able to connect to the database.
114
+
If you are using the `isUnixSocket` don't forget to add __"/.s.PGSQL.5432"__ to the end of the `host` IP address. Otherwise, your Google Cloud Run instance will not be able to connect to the database.
118
115
119
116
:::
120
117
121
118
### Connecting to AWS RDS
122
119
123
120
You can connect to an AWS RDS Instance in two ways:
121
+
124
122
1. Enable public access to the database and configure VPC/Subnets to accept your Serverpod's IP address.
125
123
2. Use the Endpoint `database-name.some-unique-id.server-location.rds.amazonaws.com` to connect to it from AWS ECS.
If the relation is defined as an [id relation](one-to-one#with-an-id-field), the default behavior is `NoAction` for onUpdate and `Cascade` for onDelete.
Copy file name to clipboardExpand all lines: docs/06-concepts/06-database/08-transactions.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
The essential point of a database transaction is that it bundles multiple steps into a single, all-or-nothing operation. The intermediate states between the steps are not visible to other concurrent transactions, and if some failure occurs that prevents the transaction from completing, then none of the steps affect the database at all.
4
4
5
-
Serverpod handles database transactions through the `session.db.transaction` method. The method takes a callback function that receives a transaction object.
5
+
Serverpod handles database transactions through the `session.db.transaction` method. The method takes a callback function that receives a transaction object.
6
6
7
7
The transaction is committed when the callback function returns, and rolled back if an exception is thrown. Any return value of the callback function is returned by the `transaction` method.
8
8
@@ -63,6 +63,7 @@ A savepoint is a special mark inside a transaction that allows all commands that
63
63
Read more about savepoints in the [PostgreSQL documentation](https://www.postgresql.org/docs/current/sql-savepoint.html).
64
64
65
65
### Creating savepoints
66
+
66
67
To create a savepoint, call the `createSavepoint` method on the transaction object:
Copy file name to clipboardExpand all lines: docs/06-concepts/06-database/10-raw-access.md
-2Lines changed: 0 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,6 @@ Simple query mode is suitable for:
33
33
* Queries containing multiple statements.
34
34
* Situations where the extended query protocol is not available (e.g., replication mode or with proxies like PGBouncer).
35
35
36
-
37
36
```dart
38
37
DatabaseResult result = await session.db.unsafeSimpleQuery(
39
38
r'SELECT * FROM mytable WHERE id = 1; SELECT * FROM othertable;'
@@ -78,4 +77,3 @@ var result = await db.unsafeQuery(
78
77
:::danger
79
78
Always sanitize your input when using raw query methods. For the `unsafeQuery` and `unsafeExecute` methods, use query parameters to prevent SQL injection. Avoid using `unsafeSimpleQuery` and `unsafeSimpleExecute` unless the simple query protocol is strictly required.
The full migration instructions can be found in the [migration guide](../database/migrations).
72
73
73
74
### Configure Authentication
74
-
Serverpod's auth module comes with a default Authentication Configuration. To customize it, go to your main `server.dart` file, import the `serverpod_auth_server` module and set up the authentication configuration:
75
75
76
+
Serverpod's auth module comes with a default Authentication Configuration. To customize it, go to your main `server.dart` file, import the `serverpod_auth_server` module and set up the authentication configuration:
76
77
77
78
```dart
78
79
import 'package:serverpod_auth_server/module.dart' as auth;
@@ -185,22 +186,27 @@ void main() async {
185
186
The `SessionManager` has useful methods for viewing and monitoring the user's current state.
186
187
187
188
#### Check authentication state
189
+
188
190
To check if the user is signed in:
189
191
190
192
```dart
191
193
sessionManager.isSignedIn;
192
194
```
195
+
193
196
Returns `true` if the user is signed in, or `false` otherwise.
194
197
195
198
#### Access current user
199
+
196
200
To retrieve information about the current user:
197
201
198
202
```dart
199
203
sessionManager.signedInUser;
200
204
```
205
+
201
206
Returns a `UserInfo` object if the user is currently signed in, or `null` if the user is not.
202
207
203
208
#### Register authentication
209
+
204
210
To register a signed in user in the session manager:
This will persist the user information and refresh any open streaming connection, see [Custom Providers - Client Setup](providers/custom-providers#client-setup) for more details.
214
221
215
222
#### Monitor authentication changes
223
+
216
224
To add a listener that tracks changes in the user's authentication state, useful for updating the UI:
217
225
218
226
```dart
@@ -226,24 +234,28 @@ void initState() {
226
234
});
227
235
}
228
236
```
237
+
229
238
The listener is triggered whenever the user's sign-in state changes.
230
239
231
240
#### Sign out current device
241
+
232
242
To sign the user out on from the current device:
233
243
234
244
```dart
235
245
await sessionManager.signOutDevice();
236
246
```
247
+
237
248
Returns `true` if the sign-out is successful, or `false` if it fails.
238
249
239
250
#### Sign out all devices
251
+
240
252
To sign the user out across all devices:
241
253
242
254
```dart
243
255
await sessionManager.signOutAllDevices();
244
256
```
245
-
Returns `true` if the user is successfully signed out from all devices, or `false` if it fails.
246
257
258
+
Returns `true` if the user is successfully signed out from all devices, or `false` if it fails.
247
259
248
260
:::info
249
261
@@ -252,4 +264,5 @@ The `signOut` method is deprecated. This method calls the deprecated `signOut` s
The behavior of `signOut` is controlled by `legacyUserSignOutBehavior`, which you can adjust in the [configure authentication](setup#configure-authentication) section. This allows you to control the signout behaviour of already shipped clients.
When a user's authentication is revoked, the server must be notified to respect the changes (e.g. to close method streams). Invoke the `session.messages.authenticationRevoked` method and raise the appropriate event to notify the server.
0 commit comments