Skip to content

Commit dc53273

Browse files
committed
documentation: create pt-br README
1 parent f930f6e commit dc53273

File tree

3 files changed

+330
-51
lines changed

3 files changed

+330
-51
lines changed

README.md

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
[![Windows Build][appveyor-image]][appveyor-url]
99
[![License][license-image]][license-url]
1010

11-
English | [简体中文](./documentation/zh-cn/)
11+
English | [简体中文](./documentation/zh-cn/) | [Português (BR)](./documentation/pt-br/)
1212

13-
> MySQL client for Node.js with focus on performance. Supports prepared statements, non-utf8 encodings, binary log protocol, compression, ssl [much more](./documentation/en)
13+
> MySQL client for Node.js with focus on performance. Supports prepared statements, non-utf8 encodings, binary log protocol, compression, ssl [much more](./documentation/en).
1414
1515
__Table of contents__
1616

@@ -20,6 +20,9 @@ __Table of contents__
2020
- [Using Prepared Statements](#using-prepared-statements)
2121
- [Using connection pools](#using-connection-pools)
2222
- [Using Promise Wrapper](#using-promise-wrapper)
23+
- [Array Results](#array-results)
24+
- [Connection Level](#connection-level)
25+
- [Query Level](#query-level)
2326
- [API and Configuration](#api-and-configuration)
2427
- [Documentation](#documentation)
2528
- [Acknowledgements](#acknowledgements)
@@ -29,7 +32,7 @@ __Table of contents__
2932

3033
MySQL2 project is a continuation of [MySQL-Native][mysql-native]. Protocol parser code was rewritten from scratch and api changed to match popular [mysqljs/mysql][node-mysql]. MySQL2 team is working together with [mysqljs/mysql][node-mysql] team to factor out shared code and move it under [mysqljs][node-mysql] organisation.
3134

32-
MySQL2 is mostly API compatible with [mysqljs][node-mysql] and supports majority of features. MySQL2 also offers these additional features
35+
MySQL2 is mostly API compatible with [mysqljs][node-mysql] and supports majority of features. MySQL2 also offers these additional features:
3336

3437
- Faster / Better Performance
3538
- [Prepared Statements](./documentation/en/Prepared-Statements.md)
@@ -51,7 +54,6 @@ npm install --save mysql2
5154
```
5255

5356
## First Query
54-
5557
```js
5658
// get the client
5759
const mysql = require('mysql2');
@@ -84,11 +86,11 @@ connection.query(
8486

8587
## Using Prepared Statements
8688

87-
With MySQL2 you also get the prepared statements. With prepared statements MySQL doesn't have to prepare plan for same query everytime, this results in better performance. If you don't know why they are important, please check these discussions
89+
With MySQL2 you also get the prepared statements. With prepared statements MySQL doesn't have to prepare plan for same query every time, this results in better performance. If you don't know why they are important, please check these discussions:
8890

8991
- [How prepared statements can protect from SQL Injection attacks](http://stackoverflow.com/questions/8263371/how-can-prepared-statements-protect-from-sql-injection-attacks)
9092

91-
MySQL provides `execute` helper which will prepare and query the statement. You can also manually prepare / unprepare statement with `prepare` / `unprepare` methods.
93+
MySQL2 provides `execute` helper which will prepare and query the statement. You can also manually prepare / unprepare statement with `prepare` / `unprepare` methods.
9294

9395
```js
9496
// get the client
@@ -144,9 +146,9 @@ The pool does not create all connections upfront but creates them on demand unti
144146
You can use the pool in the same way as connections (using `pool.query()` and `pool.execute()`):
145147
```js
146148
// For pool initialization, see above
147-
pool.query("SELECT field FROM atable", function(err, rows, fields) {
149+
pool.query("SELECT `field` FROM `table`", function(err, rows, fields) {
148150
// Connection is automatically released when query resolves
149-
})
151+
});
150152
```
151153

152154
Alternatively, there is also the possibility of manually acquiring a connection from the pool and returning it later:
@@ -157,14 +159,12 @@ pool.getConnection(function(err, conn) {
157159
conn.query(/* ... */);
158160
// Don't forget to release the connection when finished!
159161
pool.releaseConnection(conn);
160-
})
162+
});
161163
```
162164

163165
## Using Promise Wrapper
164166

165167
MySQL2 also support Promise API. Which works very well with ES7 async await.
166-
167-
<!--eslint-disable-next-block-->
168168
```js
169169
async function main() {
170170
// get the client
@@ -176,9 +176,7 @@ async function main() {
176176
}
177177
```
178178

179-
MySQL2 use default `Promise` object available in scope. But you can choose which `Promise` implementation you want to use
180-
181-
<!--eslint-disable-next-block-->
179+
MySQL2 use default `Promise` object available in scope. But you can choose which `Promise` implementation you want to use.
182180
```js
183181
// get the client
184182
const mysql = require('mysql2/promise');
@@ -193,7 +191,7 @@ const connection = await mysql.createConnection({host:'localhost', user: 'root',
193191
const [rows, fields] = await connection.execute('SELECT * FROM `table` WHERE `name` = ? AND `age` > ?', ['Morty', 14]);
194192
```
195193

196-
MySQL2 also exposes a .promise() function on Pools, so you can create a promise/non-promise connections from the same pool
194+
MySQL2 also exposes a .promise() function on Pools, so you can create a promise/non-promise connections from the same pool.
197195
```js
198196
async function main() {
199197
// get the client
@@ -207,7 +205,7 @@ async function main() {
207205
}
208206
```
209207

210-
MySQL2 exposes a .promise() function on Connections, to "upgrade" an existing non-promise connection to use promise
208+
MySQL2 exposes a .promise() function on Connections, to "upgrade" an existing non-promise connection to use promise.
211209
```js
212210
// get the client
213211
const mysql = require('mysql2');
@@ -223,30 +221,27 @@ con.promise().query("SELECT 1")
223221
.then( () => con.end());
224222
```
225223

226-
## Array results
224+
## Array Results
227225

228226
If you have two columns with the same name, you might want to get results as an array rather than an object to prevent them from clashing. This is a deviation from the [Node MySQL][node-mysql] library.
229227

230228
For example: `select 1 as foo, 2 as foo`.
231229

232230
You can enable this setting at either the connection level (applies to all queries), or at the query level (applies only to that specific query).
233231

234-
### Connection Option
232+
### Connection Level
235233
```js
236234
const con = mysql.createConnection(
237235
{ host: 'localhost', database: 'test', user: 'root', rowsAsArray: true }
238236
);
239-
240237
```
241238

242-
### Query Option
243-
239+
### Query Level
244240
```js
245241
con.query({ sql: 'select 1 as foo, 2 as foo', rowsAsArray: true }, function(err, results, fields) {
246-
console.log(results) // will be an array of arrays rather than an array of objects
247-
console.log(fields) // these are unchanged
242+
console.log(results); // in this query, results will be an array of arrays rather than an array of objects
243+
console.log(fields); // fields are unchanged
248244
});
249-
250245
```
251246

252247
## API and Configuration

0 commit comments

Comments
 (0)