11"""
22 get_table_names(source)::Tuple{Symbol}
33
4- Get the names of the tables in `source`
4+ Get the names of the tables in `source`.
5+
6+ ```jldoctest
7+ julia> using QuerySQLite
8+
9+ julia> database = Database(joinpath(pathof(QuerySQLite) |> dirname |> dirname, "test", "Chinook_Sqlite.sqlite"));
10+
11+ julia> get_table_names(getfield(database, :source))
12+ (:Album, :Artist, :Customer, :Employee, :Genre, :Invoice, :InvoiceLine, :MediaType, :Playlist, :PlaylistTrack, :Track)
13+ ```
514"""
615function get_table_names (source:: DB )
716 as_symbols (tables (source). name)
@@ -11,7 +20,16 @@ export get_table_names
1120"""
1221 get_column_names(source, table_name)::Tuple{Symbol}
1322
14- Get the names of the columns in `table_name` in `source`
23+ Get the names of the columns in `table_name` in `source`.
24+
25+ ```jldoctest example
26+ julia> using QuerySQLite
27+
28+ julia> database = Database(joinpath(pathof(QuerySQLite) |> dirname |> dirname, "test", "Chinook_Sqlite.sqlite"));
29+
30+ julia> get_column_names(getfield(database, :source), :Album)
31+ (:AlbumId, :Title, :ArtistId)
32+ ```
1533"""
1634function get_column_names (source:: DB , table_name)
1735 as_symbols (columns (source, String (table_name)). name)
@@ -21,19 +39,48 @@ export get_column_names
2139"""
2240 struct Database{Source}
2341
24- `source` need only support [`get_table_names`](@ref) and [`get_column_names`](@ref).
42+ A wrapper for an external database. `source` need only support
43+ [`get_table_names`](@ref) and [`get_column_names`](@ref).
44+
45+ ```jldoctest
46+ julia> using QuerySQLite
47+
48+ julia> database = Database(joinpath(pathof(QuerySQLite) |> dirname |> dirname, "test", "Chinook_Sqlite.sqlite"));
49+
50+ julia> database.Track
51+ ?x9 SQLite query result
52+ TrackId │ Name │ AlbumId │ MediaTypeId
53+ ────────┼───────────────────────────────────────────┼─────────┼────────────
54+ 1 │ "For Those About To Rock (We Salute You)" │ 1 │ 1
55+ 2 │ "Balls to the Wall" │ 2 │ 2
56+ 3 │ "Fast As a Shark" │ 3 │ 2
57+ 4 │ "Restless and Wild" │ 3 │ 2
58+ 5 │ "Princess of the Dawn" │ 3 │ 2
59+ 6 │ "Put The Finger On You" │ 1 │ 1
60+ 7 │ "Let's Get It Up" │ 1 │ 1
61+ 8 │ "Inject The Venom" │ 1 │ 1
62+ 9 │ "Snowballed" │ 1 │ 1
63+ 10 │ "Evil Walks" │ 1 │ 1
64+ ... with more rows, and 5 more columns: GenreId, Composer, Milliseconds, Bytes, UnitPrice
65+ ```
2566"""
2667struct Database{Source}
2768 source:: Source
2869end
2970
71+ """
72+ Database(filename::AbstractString)
73+
74+ Guess the database software from the filename.
75+ """
3076function Database (filename:: AbstractString )
3177 if endswith (filename, " .sqlite" )
3278 Database (SQLite. DB (filename))
3379 else
3480 throw (ArgumentError (" Unsupported database type for $filename " ))
3581 end
3682end
83+ export Database
3784
3885get_source (source_tables:: Database ) = getfield (source_tables, :source )
3986
0 commit comments