How to add sql3 to crystal, step by step

As a total newcomer to Crystal I have trouble doing some (basic?) things. I have gone through basic drills (syntax, etc.) and now I’d like to try some ‘real life’ coding. Before I do that, I have to figure out how to prepare my tools to do that. Instructions are very cryptic and it’d be a while until I’ll be better oriented to find the needed info. Right now I need some handholding on how to use Crystal-sqlite3, i.e: how and where to install the shard(?) . Where to put the needed .yaml. Is there anything else I have to do?

  • Create a project directory and cd to that directory.

  • Run shards init in that directory. It creates a file called shard.yml

  • Open shard.yml and add sqlite dependency(As shown in the commented example in the same file)

        github: crystal-lang/crystal-sqlite3
  • Now run shards install to install the dependencies.

  • Now create the source file under src directory. Example: src/

  • If it is a binary app, add targets to shard.yml. Example:

        main: src/
  • Once you write the code, run shards build then it will create the binary my-app under bin directory in the same project directory.

  • If no targets added then execute the files directly under src directory. Example: crystal run src/ or crystal run src/ or crystal build src/


Thanks for the help. As with every fresh start, it’s lots of new info and hard to get started yourself until you gain some orientation. Especially at my age (72)

1 Like