I'd like to store a database schema in its own file, and have my Scala code retrieve it (and execute it via JDBC).
It seems to me that sbt wants me to store the file as: src/main/resources/packagename/my.sql. Putting it there, I see it's in the jar - but I can't seem to access it from Scala.
Specifically, getClass().getResource("my.sql") returns a null pointer, and so does any other form I can think of.
How should I load the file? Or is there a better way to do it?
I had an almost identical problem.
The only difference is my file is in src/main/resources (without any packages).
This worked for me.
val is:InputStream = Github.getClass().getResourceAsStream( "/repo.json" );
Why don't you generate a file, and store it as "my.sql", and later search for it, where it appears in the filesystem?
Related
In my JS+SQLite project, I'm putting database and table creation SQL code in a separate file, to make the structure clear. What is the recommended file extension? .sql?
I feel a litte stupid for saying "yes, you got it!", but that is what it is.
The .sql-extension is used by some bigger Apps that process Databases, like SQirL and Eclipse IDE.
Keep in mind, that File extensions are purely meant to make it easier for the user to identify its content.
So basically, any extension that you deem readable is just as fine as the any other.
I'd like to specify the database schema for a query by comment. I know that you can do it for files in the settings of intelliJ. But since this information is stored in the intellij configurations (I guess) which aren't shared in our company through git, those information are lost when the project is shared through a VCS like git. And so would other people not get correct validation of the queries.
What I'd like to do is basically something like this:
#schema=foo
SELECT * FROM bar;
Which would be the same as if you write:
SELECT * from foo.bar;
For what? Basically just for code completion and validation from intellij that your query is correct and has no syntactic or logical errors. Does anyone know if there's a plugin or hidden functionality? I searched around google but didn't find anything.
E: Nice would be if you can specify those comments for the whole file or only for single queries (first one would be better, second optional)
E2: It maybe looks strange why I don't just write the second example with the schema. But if I don't write that I can load the file to e.g. java and specify the schema dynamically in my source code through the database connection.
Just use appropriate "use statements" in sql file/console. IntelliJ IDEA honors them when doing resolve, and code completion. This is implemented so that you would have the same experience when executing the sole script or within IDE. This way the script will be valid from both points: stand alone execution and IntelliJ IDEA intellisense.
I have set up a project in DataGrip with several sql files spread over a couple of directories like this:
My hope is to manage the complexity as this turns into hundreds of files. This is a learning/proof of concept level effort right now.
What I want to do is have a way to run/build/publish this project but at present the best I have found is to select the files and then do a "Run Files" CTRL+SHIFT+F10. This worked for a bit but now I have a foreign key that gets run in the wrong order. I don't want to have to make a hack like prefixing the file names with integers to force a specific order. It feels like a real kludge.
How should I accomplish this, I must have missed something since the alternative is very manual and error prone. If it matters the database I am working against is Oracle.
Since DataGrip 2020.1 one can create a Run Configuration and specify data source and multiple files or scripts:
Refer to DataGrip blog post.
OK, it may sound fairly straightforward but I'm still not sure how to go about it.
I know it's possible to check file type based on file extensions, using UTIs (e.g. Get the type of a file in Cocoa).
However, I need to be able to get the file type (in more general terms, like "text", "image", "else"), depending on the content.
Is that possible?
Any ideas?
One route forward is to call the file command and parse its output, but that is fairly horrible, and I wouldn't do that as it's slow and you are susceptible to changes in the output.
The file command uses a pretty extensive database of byte patterns to test the contents of the file and I would be tempted to implement my own internal version of it, or use this library (which I think might need some work before it works under OSX).
I am developing a Node.js project in IntelliJ.
The only way to rename files seems to be Shift+F6 which attempts to find all usages which takes too long (~30s - 1min).
Is there a way to simply rename the file without searching for usages?
This only happens when code is stored in Modules (which is necessary to be able to compact empty middle packages).
Best way I have found is to map ALT+SHIFT+F6 to Reveal in Finder. Then just press enter and type in new name.
It's good because its very similar to SHIFT+F6 rename refactor.
No.
IntelliJ must find the usages to rename them, otherwise you're just renaming the file, not refactoring. If you only want to rename the file, use the mv command from a terminal. You can also tell IntelliJ not to look in strings and text, which speeds things up somewhat, but is probably a bad idea in a javascript project (where almost everything is string or text).
I use rename a lot, and on my codebase, which is pretty big, it only takes a couple of seconds. Maybe intellij needs more memory to operate in, so you could try increasing that.
If You are doing it many times, You can create a custom scope for the refactoring:
There You can narrow the scope to few files/folders/modules etc. And for very narrow scope it will work as normal rename.