mysql-memory-server 1.5.0 → 1.6.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 CHANGED
@@ -1,8 +1,8 @@
1
1
  # MySQL Memory Server
2
2
 
3
- This package allows you to create ephemeral MySQL databases inside of Node.js, great for testing. When creating a new database, if the version selected is not installed on the system, the binary is downloaded from MySQL's CDN (cdn.mysql.com)
3
+ This package allows you to create ephemeral MySQL databases from JavaScript and/or TypeScript code, great for testing. When creating a new database, if the version selected is not installed on the system, the binary is downloaded from MySQL's CDN (cdn.mysql.com)
4
4
 
5
- You can run multiple MySQL databases with this package at the same time. Each database will use a random free port. The databases will automatically shutdown when the Node.js process exits. A `stop()` method is also provided to stop each database instance.
5
+ You can run multiple MySQL databases with this package at the same time. Each database will use a random free port. The databases will automatically shutdown when the JS runtime process exits. A `stop()` method is also provided to stop each database instance.
6
6
 
7
7
  ## Installation
8
8
 
@@ -28,10 +28,12 @@ Requirements for Linux:
28
28
  #### Currently supported MySQL versions
29
29
 
30
30
  - If using the system installed MySQL server: 8.0.20 and newer
31
- - If not using the system installed MySQL server: 8.0.39, 8.1.0, 8.2.0, 8.3.0, 8.4.2, 9.0.1
31
+ - If not using the system installed MySQL server: 8.0.39, 8.0.40, 8.1.0, 8.2.0, 8.3.0, 8.4.2, 8.4.3, 9.0.1, 9.1.0
32
32
 
33
33
  ## Usage
34
34
 
35
+ This package supports both ESM and CJS so you can use import or require.
36
+
35
37
  ```javascript
36
38
  import { createDB } from 'mysql-memory-server';
37
39
  import sql from 'mysql2/promise'
@@ -194,6 +196,16 @@ Default: 3
194
196
 
195
197
  Description: The number of times to try to download a MySQL binary before giving up and rejecting the `createDB()` promise.
196
198
 
199
+ - `initSQLString: string`
200
+
201
+ Required: No
202
+
203
+ Default: ""
204
+
205
+ Description: A string with MySQL queries to run before the database starts to accept connections. This option can be used for things like initialising tables without having to first connect to the database to do that.The queries in the string get executed after ```mysql-memory-server```'s queries run. Uses the ```--init-file``` MySQL server option under the hood. Learn more at the [--init-file MySQL Documentation](https://dev.mysql.com/doc/refman/8.4/en/server-system-variables.html#sysvar_init_file)
206
+
207
+ The internal queries that are ran before the queries in ```initSQLString``` are renaming the user from ```root``` to the username specified in the ```username``` option if it's set, and creating a database with the name from the ```dbName``` option.
208
+
197
209
  ***
198
210
  ### :warning: Internal Options :warning:
199
211
 
package/dist/src/index.js CHANGED
@@ -53,7 +53,8 @@ async function createDB(opts) {
53
53
  port: 0,
54
54
  xPort: 0,
55
55
  binaryDirectoryPath: `${os.tmpdir()}/mysqlmsn/binaries`,
56
- downloadRetries: 10
56
+ downloadRetries: 10,
57
+ initSQLString: ''
57
58
  };
58
59
  const options = { ...defaultOptions, ...opts };
59
60
  const logger = new Logger_1.default(options.logLevel);
@@ -423,6 +423,9 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
423
423
  if (options.username !== 'root') {
424
424
  initText += `\nRENAME USER 'root'@'localhost' TO '${options.username}'@'localhost';`;
425
425
  }
426
+ if (options.initSQLString.length > 0) {
427
+ initText += `\n${options.initSQLString}`;
428
+ }
426
429
  this.logger.log('Writing init file');
427
430
  await fsPromises.writeFile(`${options.dbPath}/init.sql`, initText, { encoding: 'utf8' });
428
431
  this.logger.log('Finished writing init file');
@@ -1,4 +1,109 @@
1
1
  [
2
+ {
3
+ "version": "9.1.0",
4
+ "arch": "arm64",
5
+ "os": "darwin",
6
+ "osKernelVersionsSupported": ">=22",
7
+ "url": "https://cdn.mysql.com//Downloads/MySQL-9.1/mysql-9.1.0-macos14-arm64.tar.gz"
8
+ },
9
+ {
10
+ "version": "9.1.0",
11
+ "arch": "x64",
12
+ "os": "darwin",
13
+ "osKernelVersionsSupported": ">=22",
14
+ "url": "https://cdn.mysql.com//Downloads/MySQL-9.1/mysql-9.1.0-macos14-x86_64.tar.gz"
15
+ },
16
+ {
17
+ "version": "9.1.0",
18
+ "arch": "x64",
19
+ "os": "linux",
20
+ "osKernelVersionsSupported": "*",
21
+ "url": "https://cdn.mysql.com//Downloads/MySQL-9.1/mysql-9.1.0-linux-glibc2.17-x86_64-minimal.tar.xz"
22
+ },
23
+ {
24
+ "version": "9.1.0",
25
+ "arch": "arm64",
26
+ "os": "linux",
27
+ "osKernelVersionsSupported": "*",
28
+ "url": "https://cdn.mysql.com//Downloads/MySQL-9.1/mysql-9.1.0-linux-glibc2.17-aarch64-minimal.tar.xz"
29
+ },
30
+ {
31
+ "version": "9.1.0",
32
+ "arch": "x64",
33
+ "os": "win32",
34
+ "osKernelVersionsSupported": "*",
35
+ "url": "https://cdn.mysql.com//Downloads/MySQL-9.1/mysql-9.1.0-winx64.zip"
36
+ },
37
+ {
38
+ "version": "8.4.3",
39
+ "arch": "arm64",
40
+ "os": "darwin",
41
+ "osKernelVersionsSupported": ">=22",
42
+ "url": "https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.3-macos14-arm64.tar.gz"
43
+ },
44
+ {
45
+ "version": "8.4.3",
46
+ "arch": "x64",
47
+ "os": "darwin",
48
+ "osKernelVersionsSupported": ">=22",
49
+ "url": "https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.3-macos14-x86_64.tar.gz"
50
+ },
51
+ {
52
+ "version": "8.4.3",
53
+ "arch": "x64",
54
+ "os": "linux",
55
+ "osKernelVersionsSupported": "*",
56
+ "url": "https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.3-linux-glibc2.17-x86_64-minimal.tar.xz"
57
+ },
58
+ {
59
+ "version": "8.4.3",
60
+ "arch": "arm64",
61
+ "os": "linux",
62
+ "osKernelVersionsSupported": "*",
63
+ "url": "https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.3-linux-glibc2.17-aarch64-minimal.tar.xz"
64
+ },
65
+ {
66
+ "version": "8.4.3",
67
+ "arch": "x64",
68
+ "os": "win32",
69
+ "osKernelVersionsSupported": "*",
70
+ "url": "https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.3-winx64.zip"
71
+ },
72
+ {
73
+ "version": "8.0.40",
74
+ "arch": "arm64",
75
+ "os": "darwin",
76
+ "osKernelVersionsSupported": ">=22",
77
+ "url": "https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.40-macos14-arm64.tar.gz"
78
+ },
79
+ {
80
+ "version": "8.0.40",
81
+ "arch": "x64",
82
+ "os": "darwin",
83
+ "osKernelVersionsSupported": ">=22",
84
+ "url": "https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.40-macos14-x86_64.tar.gz"
85
+ },
86
+ {
87
+ "version": "8.0.40",
88
+ "arch": "x64",
89
+ "os": "linux",
90
+ "osKernelVersionsSupported": "*",
91
+ "url": "https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.40-linux-glibc2.17-x86_64-minimal.tar.xz"
92
+ },
93
+ {
94
+ "version": "8.0.40",
95
+ "arch": "arm64",
96
+ "os": "linux",
97
+ "osKernelVersionsSupported": "*",
98
+ "url": "https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.40-linux-glibc2.17-aarch64-minimal.tar.xz"
99
+ },
100
+ {
101
+ "version": "8.0.40",
102
+ "arch": "x64",
103
+ "os": "win32",
104
+ "osKernelVersionsSupported": "*",
105
+ "url": "https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.40-winx64.zip"
106
+ },
2
107
  {
3
108
  "version": "9.0.1",
4
109
  "arch": "arm64",
@@ -1,24 +1,25 @@
1
1
  import { ExecFileException } from "child_process";
2
2
  export type LOG_LEVEL = 'LOG' | 'WARN' | 'ERROR';
3
3
  export type ServerOptions = {
4
- version?: string;
5
- dbName?: string;
6
- logLevel?: LOG_LEVEL;
7
- portRetries?: number;
8
- downloadBinaryOnce?: boolean;
9
- lockRetries?: number;
10
- lockRetryWait?: number;
11
- username?: string;
12
- deleteDBAfterStopped?: boolean;
13
- dbPath?: string;
14
- ignoreUnsupportedSystemVersion?: boolean;
15
- port?: number;
16
- xPort?: number;
17
- binaryDirectoryPath?: string;
18
- downloadRetries?: number;
4
+ version?: string | undefined;
5
+ dbName?: string | undefined;
6
+ logLevel?: LOG_LEVEL | undefined;
7
+ portRetries?: number | undefined;
8
+ downloadBinaryOnce?: boolean | undefined;
9
+ lockRetries?: number | undefined;
10
+ lockRetryWait?: number | undefined;
11
+ username?: string | undefined;
12
+ deleteDBAfterStopped?: boolean | undefined;
13
+ dbPath?: string | undefined;
14
+ ignoreUnsupportedSystemVersion?: boolean | undefined;
15
+ port?: number | undefined;
16
+ xPort?: number | undefined;
17
+ binaryDirectoryPath?: string | undefined;
18
+ downloadRetries?: number | undefined;
19
+ initSQLString?: string | undefined;
19
20
  };
20
21
  export type InternalServerOptions = {
21
- version?: string;
22
+ version?: string | undefined;
22
23
  dbName: string;
23
24
  logLevel: LOG_LEVEL;
24
25
  portRetries: number;
@@ -33,6 +34,7 @@ export type InternalServerOptions = {
33
34
  xPort: number;
34
35
  binaryDirectoryPath: string;
35
36
  downloadRetries: number;
37
+ initSQLString: string;
36
38
  };
37
39
  export type ExecutorOptions = {
38
40
  logLevel: LOG_LEVEL;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mysql-memory-server",
3
- "version": "1.5.0",
3
+ "version": "1.6.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",
@@ -16,9 +16,9 @@
16
16
  "memory database"
17
17
  ],
18
18
  "scripts": {
19
- "test": "jest --testPathIgnorePatterns=/stress-tests/ --verbose",
20
- "test:ci": "jest --testPathIgnorePatterns=/stress-tests/ --setupFilesAfterEnv ./ciSetup.js --verbose",
21
- "stress": "jest --runTestsByPath stress-tests/stress.test.ts --setupFilesAfterEnv ./ciSetup.js --verbose"
19
+ "test": "jest --testPathIgnorePatterns=/stress-tests/ --verbose --colors",
20
+ "test:ci": "jest --testPathIgnorePatterns=/stress-tests/ --setupFilesAfterEnv ./ciSetup.js --verbose --colors",
21
+ "stress": "jest --runTestsByPath stress-tests/stress.test.ts --setupFilesAfterEnv ./ciSetup.js --verbose --colors"
22
22
  },
23
23
  "engines": {
24
24
  "node": ">=16.6.0",
@@ -27,11 +27,11 @@
27
27
  "author": "Sebastian-Webster",
28
28
  "license": "MIT",
29
29
  "devDependencies": {
30
- "@babel/core": "^7.25.8",
31
- "@babel/preset-env": "^7.25.8",
32
- "@babel/preset-typescript": "^7.25.7",
30
+ "@babel/core": "^7.25.9",
31
+ "@babel/preset-env": "^7.25.9",
32
+ "@babel/preset-typescript": "^7.25.9",
33
33
  "@types/adm-zip": "^0.5.5",
34
- "@types/node": "^22.7.5",
34
+ "@types/node": "^22.7.9",
35
35
  "@types/proper-lockfile": "^4.1.4",
36
36
  "@types/semver": "^7.5.8",
37
37
  "babel-jest": "^29.7.0",