Comments (5)
No need to read 001-initial.sql, the migration will do that for you.
Moreover, the line (async () =>await inMemoryDb.public.migrate())();
is effectively scheduling a migration, but triggers it "for later" (it dettaches a promise... use a linter, and you will get a warning on this line). Dettached promises is a pattern that should be avoided as much as possible (and which is, in this case, the cause of your problem).
Thus, the 4th line is effectively executed BEFORE the migration.
This should work:
const inMemoryDb = newDb();
await inMemoryDb.public.migrate();
const skills = inMemoryDb.public.many("select * from skills where name = 'Swift'");
console.log('skills', skills);
You'll have to execute this from an async method, though.
from pg-mem.
Tests
Some kind of building (transpiling, actually) is necessary given that it's TS, so no, it is not possible to run mocha directly on ts files. When you do that on your side, I suppose that you're using ts-node or something equivalent, which is transpiling TS for you. That's also what does Webpack. Kind of an equivalent way to do the same thing.
Moreover, the current setup of pg-mem tests is using webpack because it's way faster to code that way for me. That's a matter of choice.
Ts compilation error
I dont see this problem on my side ...
from pg-mem.
Got it working.
What doesn't work is just calling migrate()
bare without specifying a path even though it's supposed to be smart enough to find the migrations folder if it's in the same directory, without specifying a migrationsPath
. But... for some reason it can't. It sets the path to undefined if you don't givce it a valid migrationsPath
The migration code also didn't report back when there was an undefined
migration path...so it just ate that damn error (or didn't error at all) which is why I saw nothing resolving or happening which is a hugely unhelpful to anyone trying to use this module. I'm adding behavior to improve that, see my last reply above.
I know that your existing test did specify a path migrationsPath: path.resolve('./src/tests/migrate'),
. So I ended up doing something similar with __dirname
via migrationsPath: path.join(__dirname, 'migrations'),
in my own code. Once I did that, stuff started working.
While it works, their migration code is a complete hack job. I want to help you improve their code.
So...I'm going to do a PR with:
- examples of it working as in an ES6 Singleton module (basically how I got my stuff working)
- adding better user feedback when migrate fails for config reasons
- adding a bit more test coverage to to the migrate.ts file you ported over from the sqlite-node repo
Later on:
- I wanna get more tests around that ported migrate code garbage and also refactor it to be cleaner (Clean Code). Together we can do better than they did
from pg-mem.
My New Tests
@oguimbal I added a couple tests in the test/migrate
folder and some new behavior to your repo in my fork which I'll submit as a PR.
I don't see my new tests or migrate tests being run though after running them via yarn test
for some reason. It's not picking them up in the test run.
pg-mem Tests
Also why pre-compile the tests? Can't you just run them on your tests folder, straight .ts. I never run my tests on compiled tests to js, it's unnecessary to setup all the precompiling of them with webpack. I honestly just wanna run tests on the .ts files using a simple mocha command, mocha runs fast by its very nature, you don't need to compile the tests physically like this, compile them on the fly using babel or something
TS
I also noticed that when I opened your project (I'm using WebStorm), TS is complaining about the migrate code. Is there any way I can turn that off? I mean you must have to be getting those errors too? The sqlite migrate code is a complete mess (I know you didn't write that and mostly ported it and tweaked it, but just saying)
from pg-mem.
it is not possible to run mocha directly on ts files
yes I'm using ts-node
in conjunction with a tsconfig
in my test folder.
I still have the problem whereas when I run your yarn test
it's not picking up my tests that I added to even an existing spec of yours though for some reason.
from pg-mem.
Related Issues (20)
- QueryFailedError: type "bit" does not exist
- INSERT w/ ON CONFLICT DO NOTHING RETURNING * is returning rows for ignored conflicts
- Bytea uses utf8 instead of hex
- @mikro-orm/[email protected] has a security issue
- Corrupted alias error when adding enum column to table with multikey index
- Deleting and re-creating table with primary key fails
- Default values are evaluated at column creation time rather than insert time HOT 3
- Stand-alone instance of pg-mem HOT 7
- `using` in table alter
- Partial constraints not working
- migrate on custom schemas does not work
- Allow table name prefixed with schema
- Docs request: getting started for Python users HOT 1
- Support for "HAVING" syntax
- pg_type table contains zero rows
- Receive problem when trying to reproduce tutorial example on my project entities HOT 3
- TypeError: DataSource is not a constructor HOT 1
- Implement the json_array_elements method
- Unknown alias error when using Group By HOT 1
- Query from node-pg-migrate that won't parse - REFERENCES
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 pg-mem.