@@ -15,42 +15,25 @@ Package: https://hex.pm/packages/exqlite
15
15
16
16
## Caveats
17
17
18
- * Prepared statements are not cached.
19
18
* Prepared statements are not immutable. You must be careful when manipulating
20
19
statements and binding values to statements. Do not try to manipulate the
21
20
statements concurrently. Keep it isolated to one process.
22
- * Simultaneous writing is not supported by SQLite3 and will not be supported
23
- here.
24
- * All native calls are run through the Dirty NIF scheduler.
25
- * Datetimes are stored without offsets. This is due to how SQLite3 handles date
26
- and times. If you would like to store a timezone, you will need to create a
27
- second column somewhere storing the timezone name and shifting it when you
28
- get it from the database. This is more reliable than storing the offset as
29
- ` +03:00 ` as it does not respect daylight savings time.
21
+ * All native calls are run through the Dirty IO NIF scheduler.
30
22
* When storing ` BLOB ` values, you have to use ` {:blob, the_binary} ` , otherwise
31
- it will be interpreted as a string.
23
+ it will be interpreted as a string.
32
24
33
25
## Installation
34
26
35
27
``` elixir
36
28
defp deps do
37
29
[
30
+ # TODO
38
31
{:exqlite , " ~> 0.17" }
39
32
]
40
33
end
41
34
```
42
35
43
-
44
36
## Configuration
45
-
46
- ### Runtime Configuration
47
-
48
- ``` elixir
49
- config :exqlite , default_chunk_size: 100
50
- ```
51
-
52
- * ` default_chunk_size ` - The chunk size that is used when multi-stepping when
53
- not specifying the chunk size explicitly.
54
37
55
38
### Compile-time Configuration
56
39
@@ -115,38 +98,30 @@ export EXQLITE_SYSTEM_CFLAGS=-I/usr/local/include/sqlcipher
115
98
export EXQLITE_SYSTEM_LDFLAGS=-L/usr/local/lib -lsqlcipher
116
99
```
117
100
118
- Once you have ` exqlite ` configured, you can use the ` : key` option in the database config to enable encryption:
101
+ Once you have ` exqlite ` build configured, you can use the ` key ` pragma to enable encryption:
119
102
120
103
``` elixir
121
- config :exqlite , key: " super-secret'
104
+ {:ok , conn} = Exqlite .open (" sqlcipher.db" )
105
+ :ok = Exqlite .execute (conn, " pragma key='super-secret'" )
122
106
```
123
107
124
108
## Usage
125
109
126
- The `Exqlite.Sqlite3 ` module usage is fairly straight forward.
110
+ The ` Exqlite ` module usage is fairly straight forward.
127
111
128
112
``` elixir
129
113
# We'll just keep it in memory right now
130
- {:ok, conn} = Exqlite.Sqlite3. open(" :memory :")
114
+ {:ok , conn} = Exqlite .open (" :memory:" )
131
115
132
116
# Create the table
133
- :ok = Exqlite.Sqlite3. execute(conn, " create table test (id integer primary key, stuff text)" )
117
+ :ok = Exqlite .execute (conn, " create table test (id integer primary key, stuff text)" )
134
118
135
119
# Prepare a statement
136
- {:ok, statement} = Exqlite.Sqlite3. prepare(conn, " insert into test (stuff) values (?1 )" )
137
- :ok = Exqlite.Sqlite3. bind(conn, statement, [" Hello world" ])
120
+ {:ok , statement} = Exqlite .prepare (conn, " insert into test (stuff) values (?1)" )
121
+ :ok = Exqlite .bind (conn, statement, [" Hello world" ])
138
122
139
123
# Step is used to run statements
140
- :done = Exqlite.Sqlite3.step(conn, statement)
141
-
142
- # Prepare a select statement
143
- {:ok, statement} = Exqlite.Sqlite3.prepare(conn, " select id, stuff from test" )
144
-
145
- # Get the results
146
- {:row, [1, " Hello world" ]} = Exqlite.Sqlite3.step(conn, statement)
147
-
148
- # No more results
149
- :done = Exqlite.Sqlite3.step(conn, statement)
124
+ :done = Exqlite .step (conn, statement)
150
125
151
126
# Release the statement.
152
127
#
@@ -155,7 +130,19 @@ The `Exqlite.Sqlite3` module usage is fairly straight forward.
155
130
#
156
131
# If you are operating at a high load issuing thousands of statements, it would be
157
132
# possible to run out of memory or cause a lot of pressure on memory.
158
- :ok = Exqlite.Sqlite3.release(conn, statement)
133
+ :ok = Exqlite .release (statement)
134
+
135
+ # Prepare a select statement
136
+ {:ok , statement} = Exqlite .prepare (conn, " select id, stuff from test" )
137
+
138
+ # Get the results
139
+ {:row , [1 , " Hello world" ]} = Exqlite .step (conn, statement)
140
+
141
+ # No more results
142
+ :done = Exqlite .step (conn, statement)
143
+
144
+ # Release the statement
145
+ :ok = Exqlite .release (statement)
159
146
```
160
147
161
148
### Using SQLite3 native extensions
@@ -164,23 +151,23 @@ Exqlite supports loading [run-time loadable SQLite3 extensions](https://www.sqli
164
151
A selection of precompiled extensions for popular CPU types / architectures is available by installing the [ ExSqlean] ( https://github.com/mindreframer/ex_sqlean ) package. This package wraps [ SQLean: all the missing SQLite functions] ( https://github.com/nalgeon/sqlean ) .
165
152
166
153
``` elixir
167
- alias Exqlite.Basic
168
- {:ok, conn} = Basic.open(" db.sqlite3" )
169
- :ok = Basic.enable_load_extension(conn)
154
+ {:ok , conn} = Exqlite .open (" :memory:" )
155
+ :ok = Exqlite .enable_load_extension (conn)
170
156
171
157
# load the regexp extension - https://github.com/nalgeon/sqlean/blob/main/docs/re.md
172
- Basic.load_extension (conn, ExSqlean.path_for(" re" ))
158
+ { :ok , _rows } = Exqlite . prepare_fetch_all (conn, " select load_extension(?) " , [ ExSqlean .path_for (" re" )] )
173
159
174
160
# run some queries to test the new `regexp_like` function
175
- {:ok, [[1]], [ " value " ] } = Basic.exec (conn, " select regexp_like (' the year is 2021' , ?) as value " , [" 2021 " ]) |> Basic.rows( )
176
- {:ok, [[0]], [ " value " ] } = Basic.exec (conn, " select regexp_like (' the year is 2021' , ?) as value " , [" 2020 " ]) |> Basic.rows( )
161
+ {:ok , [[1 ]]} = Exqlite . prepare_fetch_all (conn, " select regexp_like('the year is 2021', ?)" , [" 2021" ])
162
+ {:ok , [[0 ]]} = Exqlite . prepare_fetch_all (conn, " select regexp_like('the year is 2021', ?)" , [" 2020" ])
177
163
178
164
# prevent loading further extensions
179
- :ok = Basic.disable_load_extension(conn)
180
- {:error, %Exqlite.Error{message: " not authorized" }, _} = Basic.load_extension(conn, ExSqlean.path_for(" re" ))
165
+ :ok = Exqlite .disable_load_extension (conn)
166
+ {:error , %Exqlite .Error {message: " not authorized" }} =
167
+ Exqlite .prepare_fetch_all (conn, " select load_extension(?)" , [ExSqlean .path_for (" re" )])
181
168
182
169
# close connection
183
- Basic .close(conn)
170
+ Exqlite .close (conn)
184
171
```
185
172
186
173
## Why SQLite3
0 commit comments