當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript knex.default方法代碼示例

本文整理匯總了TypeScript中knex.default方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript knex.default方法的具體用法?TypeScript knex.default怎麽用?TypeScript knex.default使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在knex的用法示例。


在下文中一共展示了knex.default方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: makeKnex

export function makeKnex({ host, user, password, database }) {
  const knex = makeKnexConnection({
    client: 'pg',
    connection: {
      database,
      host,
      password: 'postgres',
      user,
    },
  })

  // @TODO: Figure out how to make this work with async await or Promises.
  // @TODO: See why migrations bugs out in tests.
  if (process.env.NODE_ENV !== 'test') {
    knex.migrate
      .rollback()
      .then(() => knex.migrate.latest())
      .then(() =>
        knex.seed
          .run()
          .then(() => knex)
          // tslint:disable-next-line:no-console
          .catch(e => console.error(e) && process.exit(1))
      )
  }

  return knex
}
開發者ID:marcusnielsen,項目名稱:mn-server,代碼行數:28,代碼來源:knex.ts

示例2: Knex

const getDb = (config: DbConfig): Knex => {

    if (!_db) {
        _db = Knex(config.getConfiguration());
    }

    return _db;
};
開發者ID:baotaizhang,項目名稱:fullstack-pro,代碼行數:8,代碼來源:abstract-repository.ts

示例3: Knex

test.beforeEach(t => {
  t.context.db = Knex({
    client: 'sqlite3',
    connection: {
      filename: ':memory:'
    }
  });
});
開發者ID:gitter-badger,項目名稱:overland,代碼行數:8,代碼來源:model.ts

示例4: createKnex

function createKnex(networkId: string, dbPath: string): Knex {
  logger.info(dbPath);
  if (process.env.DATABASE_URL) {
    // Be careful about non-serializable transactions. We expect database writes to be processed from the blockchain, serially, in block order.
    return Knex({
      client: "pg",
      connection: process.env.DATABASE_URL,
      postProcessResponse: postProcessDatabaseResults,
    });
  } else {
    sqlite3.verbose();
    return Knex({
      client: "sqlite3",
      connection: {
        filename: dbPath,
      },
      acquireConnectionTimeout: 5 * 60 * 1000,
      useNullAsDefault: true,
      postProcessResponse: postProcessDatabaseResults,
    });
  }
}
開發者ID:AugurProject,項目名稱:augur_node,代碼行數:22,代碼來源:check-and-initialize-augur-db.ts

示例5: beforeAll

    beforeAll(async () => {
        knex = Knex(DEFAULT_DB_CONFIG);
        await knex.migrate.latest();
        await knex.seed.run();

        const dbConfig = new DbConfig(DEFAULT_DB_CONFIG);
        container = new Container();

        container.bind<DbConfig>('DefaultDbConfig').toConstantValue(dbConfig);

        // container...
        container.bind<ICounterRepository>(TYPES.ICounterRepository).to(CounterRepository);

    });
開發者ID:baotaizhang,項目名稱:fullstack-pro,代碼行數:14,代碼來源:counter-repository.test.ts

示例6: copyRunDbFixerScript

async function copyRunDbFixerScript(dbFileNamePath: string, backupDbPath: string): Promise<void> {
  await promisify(fs.copyFile)(dbFileNamePath, backupDbPath);
  // need to do this because cli runs migrations in .ts and augur-app runs migrations in .js
  const db: Knex = Knex({
    client: "sqlite3",
    connection: {
      filename: backupDbPath,
    },
    acquireConnectionTimeout: 5 * 60 * 1000,
    useNullAsDefault: true,
  });
  await db.raw("update knex_migrations set name = substr(name,1, length(name)-2) || 'js';");
  await db.destroy();
}
開發者ID:AugurProject,項目名稱:augur_node,代碼行數:14,代碼來源:file-operations.ts

示例7: config

  private config(): void {
    // Sets the global header `Server` as a middleware. We
    // are intentionally receiving and ignoring the `req`
    // parameter, indicated by the underscore.
    this.app.use((_, res, next): void => {
      res.set("Server", "TypeScript-rest");

      next();
    });

    // Initiatlize connection to the database and connect
    // the knex query builder to our objection models.
    const knex = Knex(Knexfile);
    Model.knex(knex);
  }
開發者ID:TechEmpower,項目名稱:FrameworkBenchmarks,代碼行數:15,代碼來源:server.ts

示例8: knexInstance

    knex(tableName?: string | Knex.Raw | Knex.QueryBuilder | undefined) {
        if (!knexInstance) {
            knexInstance = Knex({
                client: 'mysql',
                connection: {
                    host: DB_HOST,
                    user: DB_USER,
                    password: DB_PASS,
                    database: WORDPRESS_DB_NAME
                }
            })
        }

        return knexInstance(tableName)
    }
開發者ID:OurWorldInData,項目名稱:owid-grapher,代碼行數:15,代碼來源:wpdb.ts

示例9: function

test('should add a new record on #save()', async function (t) {
  // startup...
  const knex = Knex({ client: 'sqlite3', connection: { filename: ':memory:' } });

  Model.knex(knex);
  Models.One.app = 'myBlog';

  const m = new Migration({ tables: [] }, { tables: [Models.One.toJSON()] });
  Migration.run(knex, await m.up());

  const one = new Models.One({ myBoolean: 1, myDate: Date.now(), myDateTime: Date.now() });
  await one.save();
  const found = await Models.One.query().where('id', 1);

  // teardown...
  await knex.destroy();
  t.same(one, found[0]);
})
開發者ID:gitter-badger,項目名稱:overland,代碼行數:18,代碼來源:model.ts

示例10: resetDatabase

  static resetDatabase(done) {
    let connection = knex({
      client    : 'mysql',
      connection: {
        user    : 'root',
        host    : '127.0.0.1',
        database: 'wetland_test',
      },
    });

    connection.raw('drop database wetland_test').then(function () {
      return connection.raw('create database wetland_test').then(() => {
        connection.destroy().then(() => {
          done();
        });
      });
    });
  }
開發者ID:RWOverdijk,項目名稱:wetland,代碼行數:18,代碼來源:Schema.ts


注:本文中的knex.default方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。