Skip to content

Commit

Permalink
doc: Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaumgartl committed Nov 14, 2024
1 parent 4471e91 commit 7511629
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MySQL data source for [Flora](https://github.com/florajs/flora), based on the [m

```js
module.exports = {
//
dataSources: {
mysql: {
constructor: require('@florajs/datasource-mysql'),
Expand All @@ -24,7 +24,7 @@ module.exports = {
password: '',
masters: [{ host: 'db01' }],
slaves: [{ host: 'db02' }, { host: 'db03' }],
}
},
specialServer: {
user: 'dbuser2',
password: '',
Expand All @@ -33,7 +33,8 @@ module.exports = {
},
},
},
//
},
};
```

Expand Down Expand Up @@ -96,7 +97,7 @@ db.insert('profiles', {

// Upsert (insert or update)
db.upsert(
'profiles',
'profiles',
{ id: 1000, firstname: 'Max' },
[ 'firstname' ] // Update firstname to "Max" if profile with id 1000 already exists
);
Expand All @@ -117,21 +118,22 @@ db.delete('profiles', { id: 1000 });
```js
const trx = await db.transaction();
try {
await trx.update('profiles', );
await trx.insert('log', );
await trx.update('profiles', { firstname: 'John', lastname: 'Doe' }, { userId: 1337 });
await trx.insert('log', { userId: 1337, msg: 'Changes applied' });
await trx.commit();
} catch (err) {
try {
// Ignore rollback errors
await trx.rollback();
} catch (ignoreErr) { }
throw err;
} catch (ignoreErr) {
throw err;
}
}

// Same as above, but shorter:
await db.transaction(async (trx) => {
await trx.update('profiles', );
await trx.insert('log', );
await trx.update('profiles', { firstname: 'John', lastname: 'Doe' }, { userId: 1337 });
await trx.insert('log', { userId: 1337, msg: 'Changes applied' });
});
```

Expand Down

0 comments on commit 7511629

Please sign in to comment.