peck
Hi everyone,
I’ve got a little hobby project (https://plaintexttides.com) that I’m working on and playing with sqlite a bit with it. I’m really only using a database to save myself some computation and API calls and speed up things, so I’m looking to use a sqlite database to essentially do that “work” ahead of time by bulk downloading the predictions at dev time vs runtime..
Essentially I’m bulk downloading and storing the tide predictions from NOAA for all the tide stations in the US for this calendar year. 4 tides, 365 days, and about 3300 stations. Not a huge amount of data, but instead of reaching out to NOAA for each time I have a user request to show the info, I have a little (~100Mb) sqlite database to query from using ecto.
I currently have it live in “priv/” and all seems to work nicely, but I don’t have a great strategy for how to “build” that database from the ground up. Using migrations, which is what I have now, doesn’t seem like quite like the “right” approach since I’ll never be doing it at runtime, but maybe it is.
Currently this is the only Repo in my app, but there’s a possibility that I could add a postgresql (or another sqlite) in the future so I want to keep options open, and since it’s a hobby project I don’t have to worry as much about YAGNI.
I was wondering if any of you had suggestions or approaches that you’ve had success with in building sqlite databases as something like static assets, maybe as a mix task or otherwise?
Thanks for any suggestions and thoughts.
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
evadne
Etso may be useful?
Bundling a 100MB file in priv over Hex would be quite heavy
Would suggest checking how tzdata handles distribution of its database. Also check approach used by evision, exla.
Eiji
The best way is to have
SQLite/CSV/JSON/XMLinprivdirectory and fetch all data at compile-time. Using said data you could generateElixircode, so you can fetch specific data using patter-matching.I wonder if storing those data in a directory with
CSVfiles (each for every table) wouldn’t be better for tasks like that. It would be not only easier to correct data manually, but also regenerate it usingElixircode.I would recommend to read this article: Welcome to our blog: how it was made! - Dashbit Blog
peck
These are great suggestions.
I do like the relational nature, and overall niceness that is ecto, so I hadn’t thought about doing the code-generation approach for this project, though I have used it successfully in the past.
To give a little more context on what my files and models look like I’ll drop them here since like I said it’s just a hobby project to give myself a playground to stay relatively up to speed on phoenix, and to scratch my own itch of being very annoyed with all the tide prediction sites covered with ads and user-hostile patterns.
The data files, that I currently have living in
/priv/predictions, are just dumps from the nice folks athttps://api.tidesandcurrents.noaa.gov/api/prod/datagetterand look like this:And to wrap things up my currently seed script is just
seeds.exsthat does this:Hasn’t been cleaned up yet, so a little messy and probably some duplicative logic in there.
But anyway at the end up it I end up with a closer to 200Mb
/priv/tide.dbsqlite database. I’m not mad about that and don’t mind the size or anything, though obviously lots of places for optimization. What I’d love to understand are some general patterns and approaches for generating static resources.Eiji
So why not to make your code work nicely like
ecto? You can collect even more data at compile-time or write your own preload functions. Just take a look at code below and see yourself how simple it is:evadne
It’s precisely the goal of Etso… or ETSo
Fill the ETS table at startup then query it with Ecto
Eiji
Not always … fetching few libraries just for simple
forloops like above does not makes much sense.axelson
I’d handle this with two parts:
Personally I like that better than a pure memory-only solution because when you restart the server you won’t need to make 3000 requests to NOAA’s API.
krasenyp
I would do what @axelson proposed but also think in a slightly different direction. If you can afford to use cached external resources, and if you expose an HTTP interface, why don’t you employ an HTTP cache, like Varnish. You can make use of cache-control and etag headers and lift the responsibility off your application.