Skip to content

Commit ffa8668

Browse files
committed
Docs update
1 parent dc4bee4 commit ffa8668

File tree

1 file changed

+21
-35
lines changed

1 file changed

+21
-35
lines changed

docs/src/index.md

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ SQLite.Source
1515
SQLite.Sink
1616
```
1717

18-
#### Types/Functions
18+
## Types/Functions
1919
* `SQLite.DB(file::AbstractString)`
2020

2121
`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
2626

2727
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.)
2828

29+
2930
* `SQLite.Stmt(db::SQLite.DB, sql::String)`
3031

3132
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).
3233

3334
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.)
3435

36+
3537
* `SQLite.bind!(stmt::SQLite.Stmt,index,value)`
3638

3739
Used to bind values to parameter placeholders in an prepared `SQLite.Stmt`. From the SQLite documentation:
@@ -48,94 +50,77 @@ SQLite.Sink
4850
4951
> 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.
5052
53+
5154
* `SQLite.execute!(stmt::SQLite.Stmt)`
5255
`SQLite.execute!(db::SQLite.DB, sql::String)`
5356

5457
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.
5558

59+
5660
* `SQLite.query(db::SQLite.DB, sql::String, values=[])`
5761

5862
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.
5963

6064
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).
6165

66+
6267
* `SQLite.drop!(db::SQLite.DB,table::String;ifexists::Bool=false)`
6368
`SQLite.dropindex!(db::SQLite.DB,index::String;ifexists::Bool=false)`
6469

6570
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.
6671

72+
6773
* `SQLite.createindex!(db::DB,table::AbstractString,index::AbstractString,cols;unique::Bool=true,ifnotexists::Bool=false)`
6874

6975
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.
7076

77+
7178
* `SQLite.removeduplicates!(db,table::AbstractString,cols::AbstractString)`
7279

7380
A convenience method for the common task of removing duplicate rows in a dataset according to some subset of columns that make up a "primary key".
7481

82+
7583
* `SQLite.tables(db::SQLite.DB)`
7684

7785
List the tables in an SQLite database `db`
7886

87+
7988
* `SQLite.columns(db::SQLite.DB,table::AbstractString)`
8089

8190
List the columns in an SQLite table
8291

92+
8393
* `SQLite.indices(db::SQLite.DB)`
8494

8595
List the indices that have been created in `db`
8696

87-
* `SQLite.Source(db::DB, sql; rows=0, stricttypes::Bool=true)`
88-
89-
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)`.
94-
95-
* `Data.stream!(source::SQLite.Source,::Type{Data.Table})`
96-
97-
Create a `Data.Table` and stream the data from an `SQLite.Source` into it.
9897

99-
* `Data.stream!(source::SQLite.Source,sink::CSV.Sink;header::Bool=true)`
100-
101-
stream the data from `source` to a `CSV.Sink`. `header` indicates whether the column names will be written first to `sink`.
102-
103-
* `SQLite.Sink(schema::Data.Schema,db::DB,tablename;temp::Bool=false,ifnotexists::Bool=true)`
104-
105-
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.
106-
107-
* `SQLite.Sink(source::Data.Source, db::DB, tablename)`
108-
109-
Create a new SQLite table as a sink in `db` according to the `Data.schema(source)`.
110-
111-
* `Data.stream!(dt::Data.Table,sink::SQLite.Sink)`
112-
113-
stream the data from a `Data.Table` to `sink`
114-
115-
* `Data.stream!(source::CSV.Source,sink::SQLite.Sink)`
98+
* `SQLite.register(db::SQLite.DB, func::Function; nargs::Int=-1, name::AbstractString=string(func), isdeterm::Bool=true)`
11699

117-
stream the data from a `CSV.Source` to `sink`
118100

119-
* `SQLite.register(db::SQLite.DB, func::Function; nargs::Int=-1, name::AbstractString=string(func), isdeterm::Bool=true)`
120101
* `SQLite.register(db::SQLite.DB, init, step::Function, final::Function=identity; nargs::Int=-1, name::AbstractString=string(final), isdeterm::Bool=true)`
121102

122103
Register a scalar (first method) or aggregate (second method) function with a `SQLite.DB`.
123104

105+
124106
* `@register db function`
125107

126108
Automatically define then register `function` with a `SQLite.DB`.
127109

110+
128111
* `sr"..."`
129112

130113
This string literal is used to escape all special characters in the string, useful for using regex in a query.
131114

115+
132116
* `SQLite.sqlreturn(contex, val)`
133117

134118
This function should never be called explicitly. Instead it is exported so that it can be overloaded when necessary, see below.
135119

136-
#### User Defined Functions
137120

138-
##### SQLite Regular Expressions
121+
## User Defined Functions
122+
123+
### SQLite Regular Expressions
139124

140125
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/))
141126

@@ -226,7 +211,8 @@ julia> SQLite.query(db, sr"SELECT * FROM MediaType WHERE Name REGEXP '-\d'")
226211

227212
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.
228213

229-
##### Custom Scalar Functions
214+
215+
### Custom Scalar Functions
230216

231217
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.
232218

@@ -278,7 +264,7 @@ sqlreturn(context, val::Bool) = sqlreturn(context, int(val))
278264

279265
Any new method defined for `sqlreturn` must take two arguments and must pass the first argument straight through as the first argument.
280266

281-
#### Custom Aggregate Functions
267+
### Custom Aggregate Functions
282268

283269
Using the `SQLite.register` function, you can also define your own aggregate functions with largely the same semantics.
284270

0 commit comments

Comments
 (0)