@@ -80,12 +80,42 @@ test.group('Query client', (group) => {
80
80
81
81
const client = new QueryClient ( 'write' , connection )
82
82
const column = await client . columnsInfo ( 'users' , 'id' )
83
- assert . deepEqual ( column , {
84
- type : 'integer' ,
85
- maxLength : null ,
86
- nullable : false ,
87
- defaultValue : null ,
83
+ assert . equal ( column . type , 'integer' )
84
+ } )
85
+
86
+ test ( 'truncate table with cascade' , async ( _assert ) => {
87
+ const connection = new Connection ( 'primary' , getConfig ( ) , getLogger ( ) )
88
+ connection . connect ( )
89
+
90
+ /**
91
+ * Create tables
92
+ */
93
+ await connection . client ?. schema . createTableIfNotExists ( 'test_users' , ( table ) => {
94
+ table . increments ( 'id' ) . primary ( )
95
+ table . string ( 'username' )
88
96
} )
97
+ await connection . client ?. schema . createTableIfNotExists ( 'test_profiles' , ( table ) => {
98
+ table . increments ( 'id' ) . primary ( )
99
+ table . integer ( 'user_id' ) . references ( 'test_users.id' ) . onDelete ( 'CASCADE' )
100
+ } )
101
+
102
+ /**
103
+ * Insert table
104
+ */
105
+ const returnValues = await connection . client ?. table ( 'test_users' ) . insert ( { username : 'virk' } )
106
+ await connection . client ?. table ( 'test_profiles' ) . insert ( { user_id : returnValues ! [ 0 ] } )
107
+
108
+ /**
109
+ * Truncate
110
+ */
111
+ const client = new QueryClient ( 'write' , connection )
112
+ await client . truncate ( 'test_users' , true )
113
+
114
+ /**
115
+ * Drop tables
116
+ */
117
+ await connection . client ?. schema . dropTable ( 'test_profiles' )
118
+ await connection . client ?. schema . dropTable ( 'test_users' )
89
119
} )
90
120
} )
91
121
0 commit comments