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: README.md
+16-17Lines changed: 16 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,30 +39,29 @@ See also:
39
39
API
40
40
---
41
41
42
-
*NOTE: the most recent release of mysql-native has been updated to be usable from `@safe` code, using the `mysql.safe` package. This document is still relevant, as the default is to use the unsafe API. Please see the [safe migration document](SAFE_MIGRATION.md) for more details*
42
+
*NOTE: the most recent release of mysql-native has been updated to be usable from `@safe` code, using the `mysql.safe` package. Please see the [safe migration document](SAFE_MIGRATION.md) for more details*
-[Connection](https://mysql-d.github.io/mysql-native/mysql/connection/Connection.html): Connection to the server, and querying and setting of server parameters.
48
-
-[MySQLPool](https://mysql-d.github.io/mysql-native/mysql/pool/MySQLPool.html): Connection pool, for Vibe.d users.
49
-
-[exec()](https://mysql-d.github.io/mysql-native/mysql/commands/exec.html): Plain old SQL statement that does NOT return rows (like INSERT/UPDATE/CREATE/etc), returns number of rows affected
50
-
-[query()](https://mysql-d.github.io/mysql-native/mysql/commands/query.html): Execute an SQL statement that DOES return rows (ie, SELECT) and handle the rows one at a time, as an input range.
51
-
-[queryRow()](https://mysql-d.github.io/mysql-native/mysql/commands/queryRow.html): Execute an SQL statement and get the first row.
52
-
-[queryValue()](https://mysql-d.github.io/mysql-native/mysql/commands/queryValue.html): Execute an SQL statement and get the first value in the first row.
53
-
-[prepare()](https://mysql-d.github.io/mysql-native/mysql/connection/prepare.html): Create a prepared statement
54
-
-[Prepared](https://mysql-d.github.io/mysql-native/mysql/prepared/Prepared.html): A prepared statement, optionally pass it to the exec/query function in place of an SQL string.
55
-
-[Row](https://mysql-d.github.io/mysql-native/mysql/result/Row.html): One "row" of results, used much like an array of Variant.
56
-
-[ResultRange](https://mysql-d.github.io/mysql-native/mysql/result/ResultRange.html): An input range of rows. Convert to random access with [std.array.array()](https://dlang.org/phobos/std_array.html#.array).
46
+
The primary interfaces (all these are the safe versions):
47
+
-[Connection](https://mysql-d.github.io/mysql-native/mysql/impl/connection/Connection.html): Connection to the server, and querying and setting of server parameters.
48
+
-[MySQLPool](https://mysql-d.github.io/mysql-native/mysql/impl/pool/MySQLPoolImpl.html): Connection pool, for Vibe.d users.
49
+
-[exec()](https://mysql-d.github.io/mysql-native/mysql/safe/commands/exec.html): Plain old SQL statement that does NOT return rows (like INSERT/UPDATE/CREATE/etc), returns number of rows affected
50
+
-[query()](https://mysql-d.github.io/mysql-native/mysql/safe/commands/query.html): Execute an SQL statement that DOES return rows (ie, SELECT) and handle the rows one at a time, as an input range.
51
+
-[queryRow()](https://mysql-d.github.io/mysql-native/mysql/safe/commands/queryRow.html): Execute an SQL statement and get the first row.
52
+
-[queryValue()](https://mysql-d.github.io/mysql-native/mysql/safe/commands/queryValue.html): Execute an SQL statement and get the first value in the first row.
53
+
-[prepare()](https://mysql-d.github.io/mysql-native/mysql/safe/connection/prepare.html): Create a prepared statement
54
+
-[Prepared](https://mysql-d.github.io/mysql-native/mysql/impl/prepared/SafePrepared.html): A prepared statement, optionally pass it to the exec/query function in place of an SQL string.
55
+
-[Row](https://mysql-d.github.io/mysql-native/mysql/impl/result/SafeRow.html): One "row" of results, used much like an array of Variant.
56
+
-[ResultRange](https://mysql-d.github.io/mysql-native/mysql/impl/result/SafeResultRange.html): An input range of rows. Convert to random access with [std.array.array()](https://dlang.org/phobos/std_array.html#.array).
57
57
58
58
Also note the [MySQL <-> D type mappings tables](https://mysql-d.github.io/mysql-native/mysql.html)
59
59
60
60
Basic example
61
61
-------------
62
62
```d
63
63
import std.array : array;
64
-
import std.variant;
65
-
import mysql;
64
+
import mysql.safe; // Please use the safe api, it's the future
66
65
67
66
void main(string[] args)
68
67
{
@@ -80,8 +79,8 @@ void main(string[] args)
80
79
// Query
81
80
ResultRange range = conn.query("SELECT * FROM `tablename`");
82
81
Row row = range.front;
83
-
Variant id = row[0];
84
-
Variant name = row[1];
82
+
MySQLVal id = row[0];
83
+
MySQLVal name = row[1];
85
84
assert(id == 1);
86
85
assert(name == "Ann");
87
86
@@ -115,7 +114,7 @@ void main(string[] args)
115
114
"INSERT INTO `tablename` (`id`, `name`) VALUES (?,?)",
116
115
null, "Cam"); // Can also take Nullable!T
117
116
range = conn.query("SELECT * FROM `tablename` WHERE `name`='Cam'");
0 commit comments