/
TableReader.vb
74 lines (59 loc) · 2.33 KB
/
TableReader.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#Region "Microsoft.VisualBasic::2e67bb6e4e5b8829ff378ffe4c371121, LINQ\Drivers\Sqlite3\Class1.vb"
' Author:
'
' asuka (amethyst.asuka@gcmodeller.org)
' xie (genetics@smrucc.org)
' xieguigang (xie.guigang@live.com)
'
' Copyright (c) 2018 GPL3 Licensed
'
'
' GNU GENERAL PUBLIC LICENSE (GPL3)
'
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
' /********************************************************************************/
' Summaries:
' Class Class1
'
'
'
' /********************************************************************************/
#End Region
Imports LINQ.Runtime.Drivers
Imports Microsoft.VisualBasic.Data.IO.ManagedSqlite.Core
Imports Microsoft.VisualBasic.Data.IO.ManagedSqlite.Core.SQLSchema
Imports Microsoft.VisualBasic.Data.IO.ManagedSqlite.Core.Tables
Imports Microsoft.VisualBasic.My.JavaScript
<DriverFlag("table")>
Public Class TableReader : Inherits DataSourceDriver
Public Sub New(arguments() As String)
MyBase.New(arguments)
End Sub
Public Overrides Iterator Function ReadFromUri(uri As String) As IEnumerable(Of Object)
Dim tableName As String = arguments(Scan0)
Dim sqlite As Sqlite3Database = Sqlite3Database.OpenFile(dbFile:=uri)
Dim rawRef As Sqlite3Table = sqlite.GetTable(tableName)
Dim rows As Sqlite3Row() = rawRef.EnumerateRows.ToArray
Dim schema As Schema = rawRef.SchemaDefinition.ParseSchema
Dim colnames As String() = schema.columns.Select(Function(c) c.Name).ToArray
For Each row As Sqlite3Row In rows
Dim jsObj As New JavaScriptObject
For i As Integer = 0 To colnames.Length - 1
jsObj(colnames(i)) = row.Item(i)
Next
Yield jsObj
Next
End Function
End Class