bookshelf.js

    0熱度

    1回答

    我遇到的問題是ES6 Arrow功能與我的Bookshelf/Bluebird承諾鏈一起正常工作。 這是工作的代碼使用ES5和藍鳥的.bind({})時: exports.prospectorLead = function (query) { return new Lead().where('id', query.lead_id).fetch({withRelated: Lead.REL

    0熱度

    1回答

    我想創建一個使用ORM Bookshelf.js的庫(如果你願意的話,基本上是一個封裝在Bookshelf.js的頂部)。現在Bookshelf.js要求您運行驅動程序安裝,以便能夠連接到項目根目錄中的正確數據庫(例如:npm install mysql)。 由於Bookshelf實例在其node_modules文件夾中沒有mysql依賴項,因此我自己的庫也需要這樣做,因爲Bookshelf.js

    0熱度

    1回答

    我想通過連接一個名爲account_id的列來使用bookshelf返回相關的行。我之前已經將這一切都工作正常,當它被'id'列鏈接時,但是由於某種原因,我們不得不將它改變爲不同的東西。 我的書架代碼看起來是這樣的: var Accounts = bookshelf.Model.extend({ tableName: 'accounts', hasTimestamps: tru

    1熱度

    2回答

    我的一般問題是,如果你有一個類似於A(1) - > B(許多) - > C(許多) - > D(許多)的數據模型,你想離開D的對象,但你只有A的標準,你怎麼做到的? 具體細節在這裏: const Contact = bookshelf.Model.extend({ sites: function() { return this.hasMany(Site); }, }

    0熱度

    1回答

    我試圖在書架的任何想法中獲得以下查詢? (這個查詢工作,並返回所需的結果) SELECT "restaurants".*, "meals".*, (select count(*) from "public"."visitors" as "visitors" where "visitors"."meal_id" = "meals"."id") as "visitorsMealsCount" FROM

    3熱度

    1回答

    我想向表中添加一列,然後執行一些工作以將該列填充爲遷移的一部分。填充列需要在代碼中進行一些操作。考慮兩個表:用戶[user_id,first_name,last_name]和Orders [order_id,user_id,other_field_1,other_field_2]。 而且功能 var getNickName = function(user_row) { //do a b

    2熱度

    1回答

    我一直在挖掘書架文檔,但找不到足夠的信息從數據庫中獲取5個隨機用戶。現在,以下代碼檢索所有用戶。 User.fetchAll().then((users) => { }); 但是,是否可以這樣做? User.take(5).random().get().then((users) => { // random 5 users in users collection }); 我

    2熱度

    1回答

    我想聲明獨立於特定連接配置的模型。 的理論代碼應該是這樣的: const connection = require('bookshelf')(knex); // Declare User model. const User = require('bookshelf') .Model .extend({ tableName: 'user' }); // Fe

    0熱度

    1回答

    我有兩個型號: const Post = Bookshelf.Model.extend({ tableName: 'post', tags: function() { return this.belongsToMany(Tag) } }); const Tag = Bookshelf.Model.extend({ tableName: 'ta

    1熱度

    1回答

    獲取最後一個記錄ID,例如,如果我有兩個表(發票,包含數量的帳單項)通過一對多關係。和後api給我的數據。新法案ID將是最後一個ID + 1,所以如果我可以做一個循環,會使物體插入然後運行 knex.insert(arrayPurchaseItems, 'id').into('purchaseRequests').then() 所以我並不需要等待紙幣插入待解決 然而,存在在賬單插入完成之前開始