mysql-memory-server 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -1
- package/dist/src/index.js +2 -1
- package/dist/src/libraries/Downloader.js +10 -8
- package/dist/src/libraries/Executor.js +11 -6
- package/dist/src/versions.json +12 -12
- package/dist/types/index.d.ts +3 -0
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ const db = await createDB()
|
|
|
32
32
|
// Connect to the new database with the port provided
|
|
33
33
|
const connection = await sql.createConnection({
|
|
34
34
|
host: '127.0.0.1',
|
|
35
|
-
user:
|
|
35
|
+
user: db.username,
|
|
36
36
|
port: db.port,
|
|
37
37
|
database: db.dbName
|
|
38
38
|
})
|
|
@@ -58,6 +58,8 @@ The port that the MySQL database is listening on
|
|
|
58
58
|
The port that MySQLX is listening on
|
|
59
59
|
- `dbName: string`
|
|
60
60
|
The database that was created on database initialization
|
|
61
|
+
- `username: string`
|
|
62
|
+
The name of the user to use to login to the database
|
|
61
63
|
- `stop: () => Promise<void>`
|
|
62
64
|
The method to stop the database. The returned promise resolves when the database has successfully stopped.
|
|
63
65
|
|
|
@@ -122,6 +124,14 @@ Default: 1,000
|
|
|
122
124
|
|
|
123
125
|
Description: If `downloadBinaryOnce` is set to `true`, `lockRetryWait` is the number of milliseconds to wait before checking if the lock has been released.
|
|
124
126
|
|
|
127
|
+
- `username: string`
|
|
128
|
+
|
|
129
|
+
Required: No
|
|
130
|
+
|
|
131
|
+
Default: root
|
|
132
|
+
|
|
133
|
+
Description: The username of the user that is used to login to the database.
|
|
134
|
+
|
|
125
135
|
## If using Ubuntu 24.04 and newer
|
|
126
136
|
|
|
127
137
|
Selecting what MySQL version to use is not currently supported on Ubuntu 24.04 and newer. To use this package on Ubuntu 24.04 and newer you must have the `mysql-server` package installed on your system and `ServerOptions.version` must either be the version that is installed on the system or undefined.
|
package/dist/src/index.js
CHANGED
|
@@ -112,18 +112,20 @@ function extractBinary(url, archiveLocation, extractedLocation) {
|
|
|
112
112
|
const zip = new adm_zip_1.default(archiveLocation);
|
|
113
113
|
const entries = zip.getEntries();
|
|
114
114
|
for (const entry of entries) {
|
|
115
|
-
if (entry.
|
|
116
|
-
if (entry.
|
|
117
|
-
|
|
115
|
+
if (entry.entryName.indexOf('..') === -1) {
|
|
116
|
+
if (entry.isDirectory) {
|
|
117
|
+
if (entry.name === folderName) {
|
|
118
|
+
await fsPromises.mkdir(`${extractedLocation}/mysql`, { recursive: true });
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
await fsPromises.mkdir(`${extractedLocation}/${entry.entryName}`, { recursive: true });
|
|
122
|
+
}
|
|
118
123
|
}
|
|
119
124
|
else {
|
|
120
|
-
await
|
|
125
|
+
const data = await getZipData(entry);
|
|
126
|
+
await fsPromises.writeFile(`${extractedLocation}/${entry.entryName}`, data);
|
|
121
127
|
}
|
|
122
128
|
}
|
|
123
|
-
else {
|
|
124
|
-
const data = await getZipData(entry);
|
|
125
|
-
await fsPromises.writeFile(`${extractedLocation}/${entry.entryName}`, data);
|
|
126
|
-
}
|
|
127
129
|
}
|
|
128
130
|
try {
|
|
129
131
|
await fsPromises.rm(archiveLocation);
|
|
@@ -123,7 +123,11 @@ class Executor {
|
|
|
123
123
|
}
|
|
124
124
|
return reject(err || stderr);
|
|
125
125
|
}
|
|
126
|
-
|
|
126
|
+
let initText = `CREATE DATABASE ${options.dbName};`;
|
|
127
|
+
if (options.username !== 'root') {
|
|
128
|
+
initText += `RENAME USER 'root'@'localhost' TO '${options.username}'@'localhost';`;
|
|
129
|
+
}
|
|
130
|
+
await fsPromises.writeFile(`${dbPath}/init.sql`, initText, { encoding: 'utf8' });
|
|
127
131
|
let retries = 0;
|
|
128
132
|
do {
|
|
129
133
|
const port = (0, Port_1.GenerateRandomPort)();
|
|
@@ -164,6 +168,10 @@ _Executor_instances = new WeakSet(), _Executor_execute = function _Executor_exec
|
|
|
164
168
|
//Once ran, resolveFunction will be called.
|
|
165
169
|
let resolveFunction;
|
|
166
170
|
process.on('close', async (code, signal) => {
|
|
171
|
+
const errorString = errors.join('\n');
|
|
172
|
+
if (errorString.includes('Address already in use')) {
|
|
173
|
+
return reject('Port is already in use');
|
|
174
|
+
}
|
|
167
175
|
try {
|
|
168
176
|
await fsPromises.rm(dbPath, { recursive: true, force: true });
|
|
169
177
|
if (binaryFilepath.includes(os.tmpdir()) && !options.downloadBinaryOnce) {
|
|
@@ -183,12 +191,8 @@ _Executor_instances = new WeakSet(), _Executor_execute = function _Executor_exec
|
|
|
183
191
|
if (code === 0) {
|
|
184
192
|
return reject('Database exited early');
|
|
185
193
|
}
|
|
186
|
-
const errorString = errors.join('\n');
|
|
187
|
-
this.logger.error(errorString);
|
|
188
|
-
if (errorString.includes('Address already in use')) {
|
|
189
|
-
return reject('Port is already in use');
|
|
190
|
-
}
|
|
191
194
|
if (code) {
|
|
195
|
+
this.logger.error(errorString);
|
|
192
196
|
return reject(errorString);
|
|
193
197
|
}
|
|
194
198
|
}
|
|
@@ -213,6 +217,7 @@ _Executor_instances = new WeakSet(), _Executor_execute = function _Executor_exec
|
|
|
213
217
|
port,
|
|
214
218
|
xPort: mySQLXPort,
|
|
215
219
|
dbName: options.dbName,
|
|
220
|
+
username: options.username,
|
|
216
221
|
stop: () => {
|
|
217
222
|
return new Promise(async (resolve, reject) => {
|
|
218
223
|
resolveFunction = resolve;
|
package/dist/src/versions.json
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
"version": "9.0.1",
|
|
4
4
|
"arch": "arm64",
|
|
5
5
|
"os": "darwin",
|
|
6
|
-
"osKernelVersionsSupported": "
|
|
6
|
+
"osKernelVersionsSupported": ">=22",
|
|
7
7
|
"url": "https://cdn.mysql.com//Downloads/MySQL-9.0/mysql-9.0.1-macos14-arm64.tar.gz"
|
|
8
8
|
},
|
|
9
9
|
{
|
|
10
10
|
"version": "9.0.1",
|
|
11
11
|
"arch": "x64",
|
|
12
12
|
"os": "darwin",
|
|
13
|
-
"osKernelVersionsSupported": "
|
|
13
|
+
"osKernelVersionsSupported": ">=22",
|
|
14
14
|
"url": "https://cdn.mysql.com//Downloads/MySQL-9.0/mysql-9.0.1-macos14-x86_64.tar.gz"
|
|
15
15
|
},
|
|
16
16
|
{
|
|
@@ -38,14 +38,14 @@
|
|
|
38
38
|
"version": "8.4.2",
|
|
39
39
|
"arch": "arm64",
|
|
40
40
|
"os": "darwin",
|
|
41
|
-
"osKernelVersionsSupported": "
|
|
41
|
+
"osKernelVersionsSupported": ">=22",
|
|
42
42
|
"url": "https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.2-macos14-arm64.tar.gz"
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
45
|
"version": "8.4.2",
|
|
46
46
|
"arch": "x64",
|
|
47
47
|
"os": "darwin",
|
|
48
|
-
"osKernelVersionsSupported": "
|
|
48
|
+
"osKernelVersionsSupported": ">=22",
|
|
49
49
|
"url": "https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.2-macos14-x86_64.tar.gz"
|
|
50
50
|
},
|
|
51
51
|
{
|
|
@@ -73,14 +73,14 @@
|
|
|
73
73
|
"version": "8.0.39",
|
|
74
74
|
"arch": "arm64",
|
|
75
75
|
"os": "darwin",
|
|
76
|
-
"osKernelVersionsSupported": "
|
|
76
|
+
"osKernelVersionsSupported": ">=22",
|
|
77
77
|
"url": "https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.39-macos14-arm64.tar.gz"
|
|
78
78
|
},
|
|
79
79
|
{
|
|
80
80
|
"version": "8.0.39",
|
|
81
81
|
"arch": "x64",
|
|
82
82
|
"os": "darwin",
|
|
83
|
-
"osKernelVersionsSupported": "
|
|
83
|
+
"osKernelVersionsSupported": ">=22",
|
|
84
84
|
"url": "https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.39-macos14-x86_64.tar.gz"
|
|
85
85
|
},
|
|
86
86
|
{
|
|
@@ -108,14 +108,14 @@
|
|
|
108
108
|
"version": "8.1.0",
|
|
109
109
|
"arch": "arm64",
|
|
110
110
|
"os": "darwin",
|
|
111
|
-
"osKernelVersionsSupported": "
|
|
111
|
+
"osKernelVersionsSupported": ">=22",
|
|
112
112
|
"url": "https://cdn.mysql.com//Downloads/MySQL-8.1/mysql-8.1.0-macos13-arm64.tar.gz"
|
|
113
113
|
},
|
|
114
114
|
{
|
|
115
115
|
"version": "8.1.0",
|
|
116
116
|
"arch": "x64",
|
|
117
117
|
"os": "darwin",
|
|
118
|
-
"osKernelVersionsSupported": "
|
|
118
|
+
"osKernelVersionsSupported": ">=22",
|
|
119
119
|
"url": "https://cdn.mysql.com//Downloads/MySQL-8.1/mysql-8.1.0-macos13-x86_64.tar.gz"
|
|
120
120
|
},
|
|
121
121
|
{
|
|
@@ -143,14 +143,14 @@
|
|
|
143
143
|
"version": "8.2.0",
|
|
144
144
|
"arch": "arm64",
|
|
145
145
|
"os": "darwin",
|
|
146
|
-
"osKernelVersionsSupported": "
|
|
146
|
+
"osKernelVersionsSupported": ">=22",
|
|
147
147
|
"url": "https://cdn.mysql.com//Downloads/MySQL-8.2/mysql-8.2.0-macos13-arm64.tar.gz"
|
|
148
148
|
},
|
|
149
149
|
{
|
|
150
150
|
"version": "8.2.0",
|
|
151
151
|
"arch": "x64",
|
|
152
152
|
"os": "darwin",
|
|
153
|
-
"osKernelVersionsSupported": "
|
|
153
|
+
"osKernelVersionsSupported": ">=22",
|
|
154
154
|
"url": "https://cdn.mysql.com//Downloads/MySQL-8.2/mysql-8.2.0-macos13-x86_64.tar.gz"
|
|
155
155
|
},
|
|
156
156
|
{
|
|
@@ -178,14 +178,14 @@
|
|
|
178
178
|
"version": "8.3.0",
|
|
179
179
|
"arch": "arm64",
|
|
180
180
|
"os": "darwin",
|
|
181
|
-
"osKernelVersionsSupported": "
|
|
181
|
+
"osKernelVersionsSupported": ">=22",
|
|
182
182
|
"url": "https://cdn.mysql.com//Downloads/MySQL-8.3/mysql-8.3.0-macos14-arm64.tar.gz"
|
|
183
183
|
},
|
|
184
184
|
{
|
|
185
185
|
"version": "8.3.0",
|
|
186
186
|
"arch": "x64",
|
|
187
187
|
"os": "darwin",
|
|
188
|
-
"osKernelVersionsSupported": "
|
|
188
|
+
"osKernelVersionsSupported": ">=22",
|
|
189
189
|
"url": "https://cdn.mysql.com//Downloads/MySQL-8.3/mysql-8.3.0-macos14-x86_64.tar.gz"
|
|
190
190
|
},
|
|
191
191
|
{
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type ServerOptions = {
|
|
|
8
8
|
downloadBinaryOnce?: boolean;
|
|
9
9
|
lockRetries?: number;
|
|
10
10
|
lockRetryWait?: number;
|
|
11
|
+
username?: string;
|
|
11
12
|
};
|
|
12
13
|
export type InternalServerOptions = {
|
|
13
14
|
version?: string;
|
|
@@ -17,6 +18,7 @@ export type InternalServerOptions = {
|
|
|
17
18
|
downloadBinaryOnce: boolean;
|
|
18
19
|
lockRetries: number;
|
|
19
20
|
lockRetryWait: number;
|
|
21
|
+
username: string;
|
|
20
22
|
};
|
|
21
23
|
export type ExecutorOptions = {
|
|
22
24
|
logLevel: LOG_LEVEL;
|
|
@@ -30,6 +32,7 @@ export type MySQLDB = {
|
|
|
30
32
|
port: number;
|
|
31
33
|
xPort: number;
|
|
32
34
|
dbName: string;
|
|
35
|
+
username: string;
|
|
33
36
|
stop: () => Promise<void>;
|
|
34
37
|
};
|
|
35
38
|
export type MySQLVersion = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mysql-memory-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Spin up an ephemeral MySQL database from your JavaScript code",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -30,5 +30,13 @@
|
|
|
30
30
|
"adm-zip": "^0.5.14",
|
|
31
31
|
"proper-lockfile": "^4.1.2",
|
|
32
32
|
"semver": "^7.6.3"
|
|
33
|
-
}
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/Sebastian-Webster/mysql-memory-server-nodejs.git"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/Sebastian-Webster/mysql-memory-server-nodejs/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/Sebastian-Webster/mysql-memory-server-nodejs"
|
|
34
42
|
}
|