You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/index.md
+21-35Lines changed: 21 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ SQLite.Source
15
15
SQLite.Sink
16
16
```
17
17
18
-
####Types/Functions
18
+
## Types/Functions
19
19
*`SQLite.DB(file::AbstractString)`
20
20
21
21
`SQLite.DB` requires the `file` string argument as the name of either a pre-defined SQLite database to be opened, or if the file doesn't exist, a database will be created.
@@ -26,12 +26,14 @@ SQLite.Sink
26
26
27
27
The `SQLite.DB` will automatically closed/shutdown when it goes out of scope (i.e. the end of the Julia session, end of a function call wherein it was created, etc.)
28
28
29
+
29
30
*`SQLite.Stmt(db::SQLite.DB, sql::String)`
30
31
31
32
Constructs and prepares (compiled by the SQLite library) an SQL statement in the context of the provided `db`. Note the SQL statement is not actually executed, but only compiled (mainly for usage where the same statement is repeated with different parameters bound as values. See `bind!` below).
32
33
33
34
The `SQLite.Stmt` will automatically closed/shutdown when it goes out of scope (i.e. the end of the Julia session, end of a function call wherein it was created, etc.)
34
35
36
+
35
37
*`SQLite.bind!(stmt::SQLite.Stmt,index,value)`
36
38
37
39
Used to bind values to parameter placeholders in an prepared `SQLite.Stmt`. From the SQLite documentation:
@@ -48,94 +50,77 @@ SQLite.Sink
48
50
49
51
> In the examples above, NNN is an integer value and AAA is an identifier. A parameter initially has a value of NULL. Prior to calling sqlite3_step() for the first time or immediately after sqlite3_reset(), the application can invoke one of the sqlite3_bind() interfaces to attach values to the parameters. Each call to sqlite3_bind() overrides prior bindings on the same parameter.
50
52
53
+
51
54
*`SQLite.execute!(stmt::SQLite.Stmt)`
52
55
`SQLite.execute!(db::SQLite.DB, sql::String)`
53
56
54
57
Used to execute a prepared `SQLite.Stmt`. The 2nd method is a convenience method to pass in an SQL statement as a string which gets prepared and executed in one call. This method does not check for or return any results, hence it is only useful for database manipulation methods (i.e. ALTER, CREATE, UPDATE, DROP). To return results, see `SQLite.query` below.
An SQL statement `sql` is prepared, executed in the context of `db`, and results, if any, are returned. The return value is a `Data.Table` by default from the `DataStreams.jl` package. The `Data.Table` has a field `.data` which is a `Vector{NullableVector}` which holds the columns of data returned from the `sql` statement.
59
63
60
64
The values in `values` are used in parameter binding (see `bind!` above). If your statement uses nameless parameters `values` must be a `Vector` of the values you wish to bind to your statment. If your statement uses named parameters `values` must be a Dict where the keys are of type `Symbol`. The key must match an identifier name in the statement (the name **should not** include the ':', '@' or '$' prefix).
These are pretty self-explanatory. They're really just a convenience methods to execute DROP TABLE/DROP INDEX commands, while also calling "VACUUM" to clean out freed memory from the database.
Create a new index named `index` for `table` with the columns in `cols`, which should be a comma delimited list of column names. `unique` indicates whether the index will have unique values or not. `ifnotexists` will not throw an error if the index already exists.
Create an `SQLite.Source` type in `db` with the SQL statement `sql`. This prepares and executes the statement, but does not return any data. The source is ready to be streamed to any sink type with an appropriate `Data.stream!` method defined. `rows` can be used to fetch a specific number of rows if known before hand and can help in pre-allocating for sinks. `stricttypes=false` can be used to relax type requirements on returned columns; typically, each value in a column must be of the same type, but SQLite itself uses a fairly weak typing scheme which allows any value to be in a column, regardless of type. Working with data in Julia is much more useful in strongly-typed structures, so by default we try to return strongly-typed columns, but this can be relaxed.
90
-
91
-
*`SQLite.Source(sink::SQLite.Sink,sql)`
92
-
93
-
Creates an `SQLite.Source` type according the `sql` command executed in the same `db` as `sink`. By default, the `sql` command is `select * from $(sink.tablename)`.
Create a new SQLite table as a sink to stream data to in `db`. `schema` is used to create the column names and types. If no `tablename` is supplied, one will be generated. `temp` indicates whether the table will be temporary, i.e. if it will be automatically destroyed when the `db` is closed.
Register a scalar (first method) or aggregate (second method) function with a `SQLite.DB`.
123
104
105
+
124
106
*`@register db function`
125
107
126
108
Automatically define then register `function` with a `SQLite.DB`.
127
109
110
+
128
111
*`sr"..."`
129
112
130
113
This string literal is used to escape all special characters in the string, useful for using regex in a query.
131
114
115
+
132
116
*`SQLite.sqlreturn(contex, val)`
133
117
134
118
This function should never be called explicitly. Instead it is exported so that it can be overloaded when necessary, see below.
135
119
136
-
#### User Defined Functions
137
120
138
-
##### SQLite Regular Expressions
121
+
## User Defined Functions
122
+
123
+
### SQLite Regular Expressions
139
124
140
125
SQLite provides syntax for calling the [`regexp` function](http://sqlite.org/lang_expr.html#regexp) from inside `WHERE` clauses. Unfortunately, however, SQLite does not provide a default implementation of the `regexp` function so SQLite.jl creates one automatically when you open a database. The function can be called in the following ways (examples using the [Chinook Database](http://chinookdatabase.codeplex.com/))
141
126
@@ -226,7 +211,8 @@ julia> SQLite.query(db, sr"SELECT * FROM MediaType WHERE Name REGEXP '-\d'")
226
211
227
212
The sr"..." currently escapes all special characters in a string but it may be changed in the future to escape only characters which are part of a regex.
228
213
229
-
##### Custom Scalar Functions
214
+
215
+
### Custom Scalar Functions
230
216
231
217
SQLite.jl also provides a way that you can implement your own [Scalar Functions](https://www.sqlite.org/lang_corefunc.html). This is done using the `register` function and macro.
0 commit comments