@@ -12,22 +12,29 @@ Install this package.
12
12
13
13
Create an entry in your ` ~/.dbt/profiles.yml ` file with the following configuration:
14
14
15
- ```
15
+ ``` YAML
16
16
dbt_sqlite :
17
17
18
18
target : dev
19
19
outputs :
20
20
dev :
21
21
type : sqlite
22
+
23
+ # sqlite locks the whole db on writes so anything > 1 won't help
22
24
threads : 1
25
+
23
26
# value of 'database' is arbitrary
24
27
database : " database"
28
+
25
29
# value of 'schema' must be defined in schema_paths below. in most cases, this should be 'main'
26
30
schema : ' main'
31
+
27
32
# connect schemas to paths: at least one of these must be 'main'
28
33
schemas_and_paths : ' main=/my_project/data/etl.db;dataset=/my_project/data/dataset_v1.db'
34
+
29
35
# directory where new schemas are created by dbt as new database files
30
36
schema_directory : ' /myproject/data/schemas'
37
+
31
38
# optional: semi-colon separated list of file paths for SQLite extensions to load.
32
39
# digesto.so is needed to provide the md5 function needed for snapshots to work.
33
40
# see section in README on how to install it
@@ -43,15 +50,26 @@ Set `profile: 'dbt_sqlite'` in your project's `dbt_project.yml` file.
43
50
stripped from the output of ` ref() ` and from SQL everywhere. It still
44
51
needs to be set in the configuration and is used by dbt internally.
45
52
46
- - Schema are implemented as attached database files. SQLite automatically
47
- assigns 'main' to the database file you initially connect to. (TODO: add warning
48
- about references and renaming schemas/database files, and what creating/schemas
49
- does)
53
+ - Schema are implemented as attached database files. (SQLite conflates databases
54
+ and schemas.)
55
+
56
+ - SQLite automatically assigns 'main' to the file you initially connect to,
57
+ so this must be defined in your profile. Other schemas defined in your profile
58
+ get attached when database connection is created.
59
+
60
+ - If dbt needs to create a new schema, it will be created in ` schema_directory ` .
61
+ Dropping a schema results in dropping all its relations but NOT detaching the
62
+ database, since this may result in a confusing conflict with the schemas you
63
+ defined in your profile.
50
64
51
- - SQLite does not allow views in one schema (i.e. database file) to reference
52
- objects in another schema. You'll get this error from SQLite: "view [ someview]
53
- cannot reference objects in database [ somedatabase] ". You must set
54
- ` materialized='table' ` in models that reference other schemas.
65
+ - Schema names are stored in view definitions, so when you access a non-'main'
66
+ database file outside dbt, you'll need to attach it using the same name, or
67
+ the views won't work.
68
+
69
+ - SQLite does not allow views in one schema (i.e. database file) to reference
70
+ objects in another schema. You'll get this error from SQLite: "view [ someview]
71
+ cannot reference objects in database [ somedatabase] ". You must set
72
+ ` materialized='table' ` in models that reference other schemas.
55
73
56
74
- Materializations are simplified: they drop and re-create the model, instead of
57
75
doing the backup-and-swap-in new mode that the other dbt database adapters
@@ -84,10 +102,7 @@ example above.
84
102
85
103
## Development Notes / TODOs
86
104
87
- - snapshots don't quite work yet, but getting there
88
-
89
- - incremental materializations seem to work but incremental test in the adapter
90
- suite fails for some reason
105
+ ...
91
106
92
107
## Running Tests
93
108
@@ -110,3 +125,8 @@ between runs of pytest, otherwise leftover state from failures can mess up subse
110
125
111
126
Inspired by this initial work by stephen1000: https://github.com/stephen1000/dbt_sqlite
112
127
128
+ https://github.com/jwills/dbt-duckdb/ - useful for ideas on working with
129
+ another embedded database
130
+
131
+ https://github.com/fishtown-analytics/dbt-spark/ - spark also has two-part
132
+ relation names (no 'database')
0 commit comments