@@ -232,6 +232,7 @@ await runtimeDb.close()
232232``` ts
233233import { Knex } from ' knex'
234234import { Database , TableBuilder } from ' @secjs/database'
235+ import database from ' ./database'
235236
236237// All SQL Drivers from Database are using Knex as query builder and for Mongo NoSQL, mongoose.
237238await database .createTable (' products' , (tableBuilder : Knex .TableBuilder ) => {
@@ -254,16 +255,17 @@ await database.createTable('product_details', (tableBuilder: Knex.TableBuilder)
254255// Changing the connection to mongo database
255256database .connection (' mongo' )
256257
257- // With mongo connection we do not have to specify the id because
258- // mongoose auto create the _id property
259- await database . createTable ( ' products ' , ( tableBuilder : TableBuilder ) => {
260- tableBuilder . string ( ' name' ). nullable ()
261- tableBuilder . integer ( ' quantity' ). nullable (). defaultTo ( 0 )
258+ // With mongo connection we can't create the table. But we can set our schema
259+ // in buildTable method
260+ const productSchema = new Schema ( {
261+ name: String ,
262+ quantity: Number ,
262263})
263264
264- await database .createTable (' product_details' , (tableBuilder : TableBuilder ) => {
265- tableBuilder .string (' detail' ).nullable ()
266- tableBuilder .integer (' productId' ).references (' id' ).inTable (' products' )
265+ database .buildTable ({
266+ name: ' Product' ,
267+ collection: ' products' ,
268+ schema: productSchema
267269})
268270
269271// Drop table products from database
0 commit comments