Skip to content
This repository was archived by the owner on Mar 18, 2022. It is now read-only.

Commit 6a1206e

Browse files
authored
Revert "fix: improve sql.js v1.0 support in browser environment"
1 parent 6429ccd commit 6a1206e

2 files changed

Lines changed: 6 additions & 56 deletions

File tree

docs/supported-platforms.md

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ You can use [sql.js](https://github.com/kripken/sql.js) in the browser.
2020
In the `browser` folder the package also includes a version compiled as a ES2015 module. If you want to use a different loader this is the point to start. Prior to TypeORM 0.1.7, the package is setup in a way that loaders like webpack will automatically use the `browser` folder. With 0.1.7 this was dropped to support Webpack usage in Node.js projects. This means, that the `NormalModuleReplacementPlugin` has to be used to insure that the correct version is loaded for browser projects. The configuration in your webpack config file, for this plugin looks like this:
2121

2222
```js
23-
// webpack.config.js
2423
plugins: [
2524
..., // any existing plugins that you already have
2625
new webpack.NormalModuleReplacementPlugin(/typeorm$/, function (result) {
2726
result.request = result.request.replace(/typeorm/, "typeorm/browser");
2827
}),
28+
new webpack.ProvidePlugin({
29+
'window.SQL': 'sql.js/js/sql.js'
30+
})
2931
]
3032
```
3133

@@ -49,57 +51,6 @@ In your main html page, you need to include reflect-metadata:
4951
<script src="./node_modules/reflect-metadata/Reflect.js"></script>
5052
```
5153

52-
### Loading Sql.js
53-
54-
From Sql.js v1.0 there are a couple of options for loading, since it comes in both pure JavaScript (asm.js) and WebAssembly versions.
55-
56-
**Using the WebAssembly version**
57-
58-
When the WebAssembly version runs in the browser, it will attempt to fetch the `sql-wasm.wasm` file from the directory where the
59-
script is located. Therefore you'll need to copy this file over as part of your build:
60-
61-
```js
62-
// webpack.config.js
63-
const CopyPlugin = require('copy-webpack-plugin');
64-
65-
plugins: [
66-
..., // any existing plugins that you already have
67-
new webpack.ProvidePlugin({
68-
'window.initSqlJs': 'sql.js',
69-
}),
70-
new CopyPlugin([
71-
{ from: 'node_modules/sql.js/dist/sql-wasm.wasm' },
72-
]),
73-
]
74-
```
75-
76-
**Using the asm.js version**
77-
78-
In this case you can omit the file copy step and just point directly to the asm.js version:
79-
80-
```js
81-
// webpack.config.js
82-
plugins: [
83-
..., // any existing plugins that you already have
84-
new webpack.ProvidePlugin({
85-
'window.initSqlJs': path.join(__dirname, 'node_modules/sql.js/dist/sql-asm.js'),
86-
}),
87-
]
88-
```
89-
90-
**Sql.js < 1.0**
91-
92-
For older versions of Sql.js, use the following webpack config:
93-
```js
94-
// webpack.config.js
95-
plugins: [
96-
..., // any existing plugins that you already have
97-
new webpack.ProvidePlugin({
98-
'window.SQL': 'sql.js'
99-
}),
100-
]
101-
```
102-
10354
## Cordova / PhoneGap / Ionic apps
10455

10556
TypeORM is able to run on Cordova, PhoneGap, Ionic apps using the

src/driver/sqljs/SqljsDriver.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import {ObjectLiteral} from "../../common/ObjectLiteral";
1212

1313
// This is needed to satisfy the typescript compiler.
1414
interface Window {
15-
SQL?: any;
16-
initSqlJs?: any;
15+
SQL: any;
1716
localforage: any;
1817
}
1918
declare var window: Window;
@@ -274,7 +273,7 @@ export class SqljsDriver extends AbstractSqliteDriver {
274273
*/
275274
protected loadDependencies(): void {
276275
if (PlatformTools.type === "browser") {
277-
this.sqlite = window.SQL || window.initSqlJs;
276+
this.sqlite = window.SQL;
278277
}
279278
else {
280279
try {
@@ -285,4 +284,4 @@ export class SqljsDriver extends AbstractSqliteDriver {
285284
}
286285
}
287286
}
288-
}
287+
}

0 commit comments

Comments
 (0)