Comments (9)
Ok. I got it to work.
I had to install sqlite3 as well. Shouldn't this be a dependency of sqlite? That wasn't very easy because it wouldn't install normally. After poking around I was able to get it to install via npm i [email protected]
to avoid the 5.0.1 issue.
Once I did that I had to change my imports a bit - the naming seems to be off here with duplicates that don't all seem to work. My working code:
import { open } from 'sqlite';
import { getLogger } from 'log4js';
import sqlite3 from 'sqlite3';
const log = getLogger();
log.level = 'DEBUG';
// this is a top-level await
(async (): Promise<void> => {
log.debug("starting");
try {
// open the database
const db = await open({
filename: '/Users/andrewjanian/projects/nodethings/things3db.sqlite',
driver: sqlite3.Database,
mode: sqlite3.OPEN_READONLY
});
log.debug(db);
const result = await db.all('SELECT * FROM TMArea');
log.debug(result);
for (const row of result) {
log.debug(row);
}
} catch (err) {
log.error(err);
}
log.debug("done");
})();
from node-sqlite.
For some history - v3 and prior used to include sqlite
, but this was difficult to maintain because someone would have to bump up the version on it with each release. Not only that, it prevented people from using the alternative sqlite3-offline
, which has precompiled binaries in situations where a complier isn't available or to reduce build times like in a CI system.
So for v4, we removed the direct dependency for it and now you specify the sqlite
library you want to use. The decoupling allows for greater flexibility because you can now pick the library you want to use with it, and it can be at any reasonable version, and reduces less maintenance on our side because we now do not have to do package bumps for the libraries.
from node-sqlite.
I'm not sure what you mean by duplicates. From quick glance, the code looks ok
also what is the problem with 5.0.1
? Usually a patch-level update shouldn't break any APIs
from node-sqlite.
@theogravity - not sure exactly what the problem is with 5.0.1 but on my mac I am not able to install 5.0.1 but I can install 5.0.0. Poking around there are others who have the same issue and that's where I got the idea to try pin 5.0.0
Regarding the duplication - duplication is probably not the right word. Before I had sqlite3 installed I was able to get OPEN_READONLY as a type definition from something called sqlite3 but there was a runtime error that sqlite3 couldn't be found. Similarly, Database (the driver) is defined in your code and also sqlite3 but fails silently if sqlite3 isn't installed. I think there are just some namespace overlaps that caused me confusion. Since I didn't have sqlite3 installed I would have assumed that I wouldn't be able to reference the types, etc.
from node-sqlite.
This is where having that flexibility come in - if this library had an explicit dependency for sqlite3
, then it'd be hard for anyone to use the version they want, especially if they encounter issues with whatever version of sqlite3
this library was pinned to.
It's actually good software practice to decouple these kinds of dependencies as much as possible because it allows for such interchangeability.
We actually have the definitions copied into this repo from sqlite3
because we'd have to include the sqlite3
package for the types, which would break the idea above.
If the definitions have changed, you can always open a PR to update.
https://github.com/kriasoft/node-sqlite/blob/master/src/vendor-typings/sqlite3/index.d.ts
from node-sqlite.
I see. The copying of the types is what threw me off. I guess I don't understand why you would have a "half-dependency" (I'll call it that) on sqlite3. I totally understand the benefit of not depending on sqlite3. OTOH that isn't totally true, right? You still depend on the types, no? I feel like copying types into your package is a code smell. TBH I don't understand enough about the innards of your package and how it works so please feel free to disregard.
from node-sqlite.
This is no different than if I wrote my own typescript definitions by hand for sqlite3
. It'd still be done without the original package being included, but why try to re-create something that already exists by hand?
The package is extremely simple if you look at the source code.
I hope with more practice in your software development, you'll eventually understand why we've decoupled it.
from node-sqlite.
from node-sqlite.
That or you can read the readme:
https://github.com/kriasoft/node-sqlite#install-sqlite3
from node-sqlite.
Related Issues (20)
- json1 extension HOT 1
- Best way to batch create/insert or update? (How to properly use driver.serialize?) HOT 1
- Can't execute transaction HOT 3
- placeholders don't work with pragma HOT 2
- SQLCipher support HOT 2
- Problem with nullable fields in knex HOT 1
- Placeholders don't work with exec
- Exceptions don't always contain stack traces HOT 3
- The callback error does not work and an exception error is generated! HOT 4
- electron-forge make error HOT 1
- Access sqlite database which has password HOT 1
- migration logic HOT 2
- impossible to change migration configuration HOT 2
- sqlite api to create a db HOT 4
- Date and time in db.run HOT 3
- Getting multiple errors in React TypeScript HOT 1
- bun.sh driver? HOT 2
- Why are sqlite3 typings included here when sqlite3 has its own typings? HOT 9
- Unable to install Sqlite HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-sqlite.