Nesting sqlite drizzle into a deeper location in my ts app, difficulties with src/ vs dist/

Hey! I'm very new to drizzle and trying to set up a very small drizzle instance for a service that reads a whole pile of json files and acts as a simple read-only information store. I got most of the setup to work. I have it at a location
src/
--services/
----this-service/
------drizzle.config.ts
------sqlite.db
------schema.ts
------this-service.db.ts
src/
--services/
----this-service/
------drizzle.config.ts
------sqlite.db
------schema.ts
------this-service.db.ts
I have some the command in my package.json
"migrate:this-service": "cd ./src/services/this-service && drizzle-kit push:sqlite"
"migrate:this-service": "cd ./src/services/this-service && drizzle-kit push:sqlite"
This works, but it appears that once I build, the sqlite isn't copied over to the /dist directory. When I then try to call this-service.db.ts, after instantiating drizzle on sqlite in its directory, it doesn't see any of the proper tables from the schema in the sqlite.db file. Is there a way to make this work? Or do I have to move this all to the root directory? One option would be is if there are importable drizzle kit functions to replicate the CLI options. I didn't see that in the documentation. Is that possible?
6 Replies
Angelelz
Angelelz16mo ago
You need to tell your build tool to copy whatever you need to your dist folder Most likely you need to add the db filetype to your include field in your tsconfig.json
significantotter
significantotterOP16mo ago
hm, typescript is annoying about this. They don't like to copy non ts assets. https://github.com/microsoft/TypeScript/issues/30835 But that's very helpful direction, and I'm looking at doing that now
GitHub
Typescript compiler --copy-files option to copy non-typescript file...
Search Terms typescript tsc copy files Suggestion The typescript compiler should have an option to copy non-compiled files, similarly to Babel: https://babeljs.io/docs/en/babel-cli#copy-files Use C...
Angelelz
Angelelz16mo ago
You could treat your db file like the assets folder, have a DB folder for your database only, at the root, and point to it from both your src and your dist
significantotter
significantotterOP16mo ago
True. I'm just trying to contain it to the service. I had considered that if I don't have other options. I'm currently using objection + pgsql for the main db work here. I just wanted a small embedded read store for this service. I plan to eventually migrate from objection to drizzle for that pg database, so I wanted to leave this one more encapsulated But yeah! Fixed it with a copyfiles tool to get the asset over. Now I'm trying to get drizzle kit studio to work with it. I'm running it in my dist directory. I can open the sqlite file and see the data. But drizzle kit studio shows an empty db Hmm... I think I see the issue when I run drizzle kit studio in the /dist directory, my schema is still referenced as './schema.ts' which fails against the compiled code. So it sees db url, but can't find the schema hm, maybe I have no choice but to move it to the top level. Would that cause issues for a later drizzle pg database in the same env as the drizzle sqlite database?
Angelelz
Angelelz16mo ago
You can pass a different configuration
significantotter
significantotterOP16mo ago
ah! That's helpful
Want results from more Discord servers?
Add your server