Category:Wren-sql

From Rosetta Code
Library
This is an example of a library. You may see a list of other libraries used on Rosetta Code at Category:Solutions by Library.

Wren-sql is a module which enables SQLite databases to be created, accessed and manipulated by the Wren programmer. It consists of five classes: Sql, Connection, Statement, Blob and Backup though it should rarely be necessary to deal with the third and fourth of these directly.

It is the thirty-first in a series of modules (listed on the main page) designed to assist with writing Rosetta Code tasks so the same code does not have to be written or copy/pasted time and time again thereby bloating a task's script code unnecessarily.

To use it you need to copy the Wren source code (in the talk page) to a text file called sql.wren and place this in the same directory as the importing script so the Wren-sql executable can find it.

Currently, Wren-cli does not support plug-ins though this or similar functionality is likely to be added in a future version (it's already present in DOME). Consequently, scripts using the Wren-sql module must be run under the control of a special executable whose source code (wren-sql.c) is also included in the talk page. This executable translates Wren method calls to calls to the corresponding SQLite functions and can be built with a command line such as the following using GCC under Linux:

   $ gcc -O3 -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_THREADSAFE=0 wren-sql.c -o wren-sql -lsqlite3 -lwren -lm

though you may want to produce a somewhat leaner or more efficient executable by using additional compile time options (see here).

If you then want to run a script called myscript.wren you would type at the command-line:

   $ ./wren-sql myscript.wren

myscript.wren should include a line such as the following to import the classes you want to use in that particular script:

   import "./sql" for Sql, Connection, Backup

The same executable can be used to run any other Wren-sql scripts unless they require additional functionality not available in Wren itself in which case the C code will need to be suitably modified and recompiled.

As mentioned on their website, the code for SQLite is in the public domain and is thus free for use for any purpose, commercial or private.

Pages in category "Wren-sql"

The following 2 pages are in this category, out of 2 total.