Skip to content

Commit 4d2bf32

Browse files
committed
Refactor: dialect/sqlite: move SQLs from main.go to *.sql using "embed"
1 parent 005bee6 commit 4d2bf32

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

dialect/sqlite/columns.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PRAGMA {schema.}table_info({table})

dialect/sqlite/main.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sqlite
22

33
import (
44
"database/sql"
5+
_ "embed"
56
"fmt"
67
"strings"
78
"time"
@@ -12,17 +13,18 @@ import (
1213
"github.com/hymkor/sqlbless/internal/misc"
1314
)
1415

16+
//go:embed tables.sql
17+
var tablesSql string
18+
19+
//go:embed columns.sql
20+
var columnsSql string
21+
1522
var Entry = &dialect.Entry{
16-
Usage: "sqlbless sqlite3 :memory: OR <FILEPATH>",
17-
SQLForTables: `
18-
select 'main' as schema,name,rootpage,sql from sqlite_master
19-
where type = 'table'
20-
union all
21-
select 'temp' as schema,name,rootpage,sql from sqlite_temp_master
22-
where type = 'table'`,
23+
Usage: "sqlbless sqlite3 :memory: OR <FILEPATH>",
24+
SQLForTables: tablesSql,
2325
TypeConverterFor: typeNameToConv,
2426
PlaceHolder: &placeHolder{},
25-
SQLForColumns: `PRAGMA {schema.}table_info({table})`,
27+
SQLForColumns: columnsSql,
2628
TableNameField: "name",
2729
ColumnNameField: "name",
2830
IsTransactionSafe: canUseInTransaction,

dialect/sqlite/tables.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
select 'main' as schema,
2+
name,
3+
rootpage,
4+
sql
5+
from sqlite_master
6+
where type = 'table'
7+
union all
8+
select 'temp' as schema,
9+
name,
10+
rootpage,
11+
sql
12+
from sqlite_temp_master
13+
where type = 'table'

0 commit comments

Comments
 (0)