How to use the schema function from knex

Find comprehensive JavaScript knex.schema code examples handpicked from public code repositorys.

29
30
31
32
33
34
35
36
37
38
await knex('test_table').truncate()

console.log('See Transaction...')
await knex.transaction(async trx => {  
  await knex('test_table').insert({ name: 'aa' }).transacting(trx)
  // await knex.schema.raw('SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;')
  let rv = await knex.select().from('test_table')
  console.log(rv)

  await knex('test_table').insert({ name: 'bb' }).transacting(trx)
fork icon116
star icon447
watch icon29

+ 11 other calls in file

24
25
26
27
28
29
30
31
32
33
34
35
36
const tablePool = {};


const loadSchema = async (knex, tableName, tableConfig) => {
	const { primaryKey, charset, schema, indexes } = tableConfig;


	if (await knex.schema.hasTable(tableName)) return knex;


	await knex.schema
		.createTable(tableName, table => {
			if (charset) table.charset(charset);
fork icon17
star icon28
watch icon0

+ 19 other calls in file

80
81
82
83
84
85
86
87
88
89
90
  console.log(data);
  knex.destroy();
}


async function createTable() {
  // await knex.schema.createTable('users2', (table) => {
  //   table.increments();
  //   table.string('name');
  //   table.timestamps();
  // });
fork icon0
star icon0
watch icon1

+ 23 other calls in file

13
14
15
16
17
18
19
20
21
22
  //OtroMas.createUser({username:"aabadin@gmail.com2",password:"111",isVerified:true,mail:"aabadin@gmail.com"	}).then(()=>console.log("fin"))
//OtroMas.findById(2,(e,res)=>console.log(res,e))
OtroMas.findByUserName("aabadin@gmail.com").then((res)=>console.log(res))
OtroMas.returnFields().then((res)=>console.log(res))
// console.log(OtroMas.db("users"),"USERS")
  // knex.schema.alterTable("goa",table=>{
//   table.dropColumn("password")
// }).then(()=>console.log("borrado"))
//const DAO =new SqlDAO(tabla1,"localSchema")
// DAO.hasField("username").then(e=>console.log(e))
fork icon0
star icon0
watch icon0

14
15
16
17
18
19
20
21
22
23
24
25


const { faker } = require("@faker-js/faker");
const { toNamespacedPath } = require("path");


const insertDummyData = async () => {
  await knex.schema.dropTableIfExists("users");
  await knex.schema.createTable("users", (table) => {
    table.increments("id");
    table.string("first_name", 50);
    table.string("last_name", 50);
fork icon0
star icon0
watch icon0

+ 3 other calls in file