Last active
September 2, 2018 00:12
-
-
Save prantlf/2afd29c30130c9beef64 to your computer and use it in GitHub Desktop.
Helps obtaining and using a local copy of the Northwind database in MongoDB and testing an OData server with JayData
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creates a local copy of the Northwind database in mongodb | |
// | |
// Requires Northwind.js with the Northwind database schema | |
const q = require('q'); | |
require('odata-server'); | |
require('./Northwind'); | |
var remote = new NorthwindContext({ | |
name: 'oData', | |
oDataServiceHost: 'http://services.odata.org/Northwind/Northwind.svc' | |
}), | |
local = new NorthwindContext({ | |
name: 'mongoDB', | |
databaseName: 'Northwind' | |
}), | |
collections = [ | |
'Categories', | |
'Customers', | |
'Employees', | |
'Order_Details', | |
'Orders', | |
'Products', | |
'Shippers', | |
'Suppliers' | |
]; | |
q.all([remote.onReady(), local.onReady()]) | |
.then(function () { | |
collections.forEach(function (collection) { | |
var from = remote[collection]; | |
from.take(10).toArray().then(function (items) { | |
function copy(items) { | |
console.log(collection, 'loaded', items.length); | |
total += items.length; | |
to.addMany(items); | |
return to.saveChanges().then(function (saved) { | |
console.log(collection, 'saved', saved); | |
return items.next().then(function (items) { | |
return items.length > 0 && copy(items); | |
}, function (error) { | |
console.log(collection, 'next failed', error); | |
}); | |
}, function (error) { | |
console.log(collection, 'save failed', error.toString()); | |
}); | |
} | |
var to = local[collection], | |
total = 0; | |
return copy(items).then(function () { | |
console.log(collection, 'copied', total); | |
});; | |
}, function (error) { | |
console.log(collection, 'load failed', error); | |
}); | |
}); | |
}, function (error) { | |
console.log('connect', error); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Drops the local Northwind database from mongodb | |
const mongo = require('mongodb').MongoClient; | |
mongo.connect('mongodb://localhost:27017/Northwind', function (err, db) { | |
if (err) { | |
console.log('connect failed', err); | |
} else { | |
db.dropDatabase(function (err, done) { | |
if (err) { | |
console.log('drop failed', err); | |
} else { | |
console.log('dropped', done); | |
} | |
db.close(function (err) { | |
if (err) { | |
console.log('close failed', err); | |
} else { | |
console.log('closed'); | |
} | |
}); | |
}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Northwind database schema for JayData | |
// | |
// Initially generated by JaySvcUtil on 2014/07/27 | |
// using http://services.odata.org/Northwind/Northwind.svc/$metadata | |
// | |
// Sample usage with a local Northwind database, which you can get | |
// by running northwind-create.js with mongodb, for example: | |
// | |
// var context = new NorthwindContext({ | |
// name: 'mongoDB', | |
// databaseName: 'Northwind' | |
// }), | |
// context.onReady().then(function (db) { | |
// ... | |
// }, function (error) { | |
// ... | |
// }); | |
(function($data, undefined) { | |
$data.Entity.extend('NorthwindModel.Category', { | |
'CategoryID': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true }, | |
'CategoryName': { 'type':'Edm.String','nullable':false,'required':true,'maxLength':15 }, | |
'Description': { 'type':'Edm.String','maxLength':Number.POSITIVE_INFINITY }, | |
'Picture': { 'type':'Edm.Binary','maxLength':Number.POSITIVE_INFINITY }, | |
'Products': { 'type':'Array','elementType':'NorthwindModel.Product','inverseProperty':'Category' } | |
}); | |
$data.Entity.extend('NorthwindModel.CustomerDemographic', { | |
'CustomerTypeID': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':10 }, | |
'CustomerDesc': { 'type':'Edm.String','maxLength':Number.POSITIVE_INFINITY }, | |
'Customers': { 'type':'Array','elementType':'NorthwindModel.Customer','inverseProperty':'CustomerDemographics' } | |
}); | |
$data.Entity.extend('NorthwindModel.Customer', { | |
'CustomerID': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':5 }, | |
'CompanyName': { 'type':'Edm.String','nullable':false,'required':true,'maxLength':40 }, | |
'ContactName': { 'type':'Edm.String','maxLength':30 }, | |
'ContactTitle': { 'type':'Edm.String','maxLength':30 }, | |
'Address': { 'type':'Edm.String','maxLength':60 }, | |
'City': { 'type':'Edm.String','maxLength':15 }, | |
'Region': { 'type':'Edm.String','maxLength':15 }, | |
'PostalCode': { 'type':'Edm.String','maxLength':10 }, | |
'Country': { 'type':'Edm.String','maxLength':15 }, | |
'Phone': { 'type':'Edm.String','maxLength':24 }, | |
'Fax': { 'type':'Edm.String','maxLength':24 }, | |
'Orders': { 'type':'Array','elementType':'NorthwindModel.Order','inverseProperty':'Customer' }, | |
'CustomerDemographics': { 'type':'Array','elementType':'NorthwindModel.CustomerDemographic','inverseProperty':'Customers' } | |
}); | |
$data.Entity.extend('NorthwindModel.Employee', { | |
'EmployeeID': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true }, | |
'LastName': { 'type':'Edm.String','nullable':false,'required':true,'maxLength':20 }, | |
'FirstName': { 'type':'Edm.String','nullable':false,'required':true,'maxLength':10 }, | |
'Title': { 'type':'Edm.String','maxLength':30 }, | |
'TitleOfCourtesy': { 'type':'Edm.String','maxLength':25 }, | |
'BirthDate': { 'type':'Edm.DateTime' }, | |
'HireDate': { 'type':'Edm.DateTime' }, | |
'Address': { 'type':'Edm.String','maxLength':60 }, | |
'City': { 'type':'Edm.String','maxLength':15 }, | |
'Region': { 'type':'Edm.String','maxLength':15 }, | |
'PostalCode': { 'type':'Edm.String','maxLength':10 }, | |
'Country': { 'type':'Edm.String','maxLength':15 }, | |
'HomePhone': { 'type':'Edm.String','maxLength':24 }, | |
'Extension': { 'type':'Edm.String','maxLength':4 }, | |
'Photo': { 'type':'Edm.Binary','maxLength':Number.POSITIVE_INFINITY }, | |
'Notes': { 'type':'Edm.String','maxLength':Number.POSITIVE_INFINITY }, | |
'ReportsTo': { 'type':'Edm.Int32' }, | |
'PhotoPath': { 'type':'Edm.String','maxLength':255 }, | |
'Employees1': { 'type':'Array','elementType':'NorthwindModel.Employee','inverseProperty':'Employee1' }, | |
'Employee1': { 'type':'NorthwindModel.Employee','inverseProperty':'Employees1' }, | |
'Orders': { 'type':'Array','elementType':'NorthwindModel.Order','inverseProperty':'Employee' }, | |
'Territories': { 'type':'Array','elementType':'NorthwindModel.Territory','inverseProperty':'Employees' } | |
}); | |
$data.Entity.extend('NorthwindModel.Order_Detail', { | |
'OrderID': { 'key':true,'type':'Edm.Int32','nullable':false,'required':true }, | |
'ProductID': { 'key':true,'type':'Edm.Int32','nullable':false,'required':true }, | |
'UnitPrice': { 'type':'Edm.Decimal','nullable':false,'required':true }, | |
'Quantity': { 'type':'Edm.Int16','nullable':false,'required':true }, | |
'Discount': { 'type':'Edm.Single','nullable':false,'required':true }, | |
'Order': { 'type':'NorthwindModel.Order','required':true,'inverseProperty':'Order_Details' }, | |
'Product': { 'type':'NorthwindModel.Product','required':true,'inverseProperty':'Order_Details' } | |
}); | |
$data.Entity.extend('NorthwindModel.Order', { | |
'OrderID': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true }, | |
'CustomerID': { 'type':'Edm.String','maxLength':5 }, | |
'EmployeeID': { 'type':'Edm.Int32' }, | |
'OrderDate': { 'type':'Edm.DateTime' }, | |
'RequiredDate': { 'type':'Edm.DateTime' }, | |
'ShippedDate': { 'type':'Edm.DateTime' }, | |
'ShipVia': { 'type':'Edm.Int32' }, | |
'Freight': { 'type':'Edm.Decimal' }, | |
'ShipName': { 'type':'Edm.String','maxLength':40 }, | |
'ShipAddress': { 'type':'Edm.String','maxLength':60 }, | |
'ShipCity': { 'type':'Edm.String','maxLength':15 }, | |
'ShipRegion': { 'type':'Edm.String','maxLength':15 }, | |
'ShipPostalCode': { 'type':'Edm.String','maxLength':10 }, | |
'ShipCountry': { 'type':'Edm.String','maxLength':15 }, | |
'Customer': { 'type':'NorthwindModel.Customer','inverseProperty':'Orders' }, | |
'Employee': { 'type':'NorthwindModel.Employee','inverseProperty':'Orders' }, | |
'Order_Details': { 'type':'Array','elementType':'NorthwindModel.Order_Detail','inverseProperty':'Order' }, | |
'Shipper': { 'type':'NorthwindModel.Shipper','inverseProperty':'Orders' } | |
}); | |
$data.Entity.extend('NorthwindModel.Product', { | |
'ProductID': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true }, | |
'ProductName': { 'type':'Edm.String','nullable':false,'required':true,'maxLength':40 }, | |
'SupplierID': { 'type':'Edm.Int32' }, | |
'CategoryID': { 'type':'Edm.Int32' }, | |
'QuantityPerUnit': { 'type':'Edm.String','maxLength':20 }, | |
'UnitPrice': { 'type':'Edm.Decimal' }, | |
'UnitsInStock': { 'type':'Edm.Int16' }, | |
'UnitsOnOrder': { 'type':'Edm.Int16' }, | |
'ReorderLevel': { 'type':'Edm.Int16' }, | |
'Discontinued': { 'type':'Edm.Boolean','nullable':false,'required':true }, | |
'Category': { 'type':'NorthwindModel.Category','inverseProperty':'Products' }, | |
'Order_Details': { 'type':'Array','elementType':'NorthwindModel.Order_Detail','inverseProperty':'Product' }, | |
'Supplier': { 'type':'NorthwindModel.Supplier','inverseProperty':'Products' } | |
}); | |
$data.Entity.extend('NorthwindModel.Region', { | |
'RegionID': { 'key':true,'type':'Edm.Int32','nullable':false,'required':true }, | |
'RegionDescription': { 'type':'Edm.String','nullable':false,'required':true,'maxLength':50 }, | |
'Territories': { 'type':'Array','elementType':'NorthwindModel.Territory','inverseProperty':'Region' } | |
}); | |
$data.Entity.extend('NorthwindModel.Shipper', { | |
'ShipperID': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true }, | |
'CompanyName': { 'type':'Edm.String','nullable':false,'required':true,'maxLength':40 }, | |
'Phone': { 'type':'Edm.String','maxLength':24 }, | |
'Orders': { 'type':'Array','elementType':'NorthwindModel.Order','inverseProperty':'Shipper' } | |
}); | |
$data.Entity.extend('NorthwindModel.Supplier', { | |
'SupplierID': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true }, | |
'CompanyName': { 'type':'Edm.String','nullable':false,'required':true,'maxLength':40 }, | |
'ContactName': { 'type':'Edm.String','maxLength':30 }, | |
'ContactTitle': { 'type':'Edm.String','maxLength':30 }, | |
'Address': { 'type':'Edm.String','maxLength':60 }, | |
'City': { 'type':'Edm.String','maxLength':15 }, | |
'Region': { 'type':'Edm.String','maxLength':15 }, | |
'PostalCode': { 'type':'Edm.String','maxLength':10 }, | |
'Country': { 'type':'Edm.String','maxLength':15 }, | |
'Phone': { 'type':'Edm.String','maxLength':24 }, | |
'Fax': { 'type':'Edm.String','maxLength':24 }, | |
'HomePage': { 'type':'Edm.String','maxLength':Number.POSITIVE_INFINITY }, | |
'Products': { 'type':'Array','elementType':'NorthwindModel.Product','inverseProperty':'Supplier' } | |
}); | |
$data.Entity.extend('NorthwindModel.Territory', { | |
'TerritoryID': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':20 }, | |
'TerritoryDescription': { 'type':'Edm.String','nullable':false,'required':true,'maxLength':50 }, | |
'RegionID': { 'type':'Edm.Int32','nullable':false,'required':true }, | |
'Region': { 'type':'NorthwindModel.Region','required':true,'inverseProperty':'Territories' }, | |
'Employees': { 'type':'Array','elementType':'NorthwindModel.Employee','inverseProperty':'Territories' } | |
}); | |
$data.Entity.extend('NorthwindModel.Alphabetical_list_of_product', { | |
'ProductID': { 'key':true,'type':'Edm.Int32','nullable':false,'required':true }, | |
'ProductName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':40 }, | |
'SupplierID': { 'type':'Edm.Int32' }, | |
'CategoryID': { 'type':'Edm.Int32' }, | |
'QuantityPerUnit': { 'type':'Edm.String','maxLength':20 }, | |
'UnitPrice': { 'type':'Edm.Decimal' }, | |
'UnitsInStock': { 'type':'Edm.Int16' }, | |
'UnitsOnOrder': { 'type':'Edm.Int16' }, | |
'ReorderLevel': { 'type':'Edm.Int16' }, | |
'Discontinued': { 'key':true,'type':'Edm.Boolean','nullable':false,'required':true }, | |
'CategoryName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':15 } | |
}); | |
$data.Entity.extend('NorthwindModel.Category_Sales_for_1997', { | |
'CategoryName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':15 }, | |
'CategorySales': { 'type':'Edm.Decimal' } | |
}); | |
$data.Entity.extend('NorthwindModel.Current_Product_List', { | |
'ProductID': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true }, | |
'ProductName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':40 } | |
}); | |
$data.Entity.extend('NorthwindModel.Customer_and_Suppliers_by_City', { | |
'City': { 'type':'Edm.String','maxLength':15 }, | |
'CompanyName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':40 }, | |
'ContactName': { 'type':'Edm.String','maxLength':30 }, | |
'Relationship': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':9 } | |
}); | |
$data.Entity.extend('NorthwindModel.Invoice', { | |
'ShipName': { 'type':'Edm.String','maxLength':40 }, | |
'ShipAddress': { 'type':'Edm.String','maxLength':60 }, | |
'ShipCity': { 'type':'Edm.String','maxLength':15 }, | |
'ShipRegion': { 'type':'Edm.String','maxLength':15 }, | |
'ShipPostalCode': { 'type':'Edm.String','maxLength':10 }, | |
'ShipCountry': { 'type':'Edm.String','maxLength':15 }, | |
'CustomerID': { 'type':'Edm.String','maxLength':5 }, | |
'CustomerName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':40 }, | |
'Address': { 'type':'Edm.String','maxLength':60 }, | |
'City': { 'type':'Edm.String','maxLength':15 }, | |
'Region': { 'type':'Edm.String','maxLength':15 }, | |
'PostalCode': { 'type':'Edm.String','maxLength':10 }, | |
'Country': { 'type':'Edm.String','maxLength':15 }, | |
'Salesperson': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':31 }, | |
'OrderID': { 'key':true,'type':'Edm.Int32','nullable':false,'required':true }, | |
'OrderDate': { 'type':'Edm.DateTime' }, | |
'RequiredDate': { 'type':'Edm.DateTime' }, | |
'ShippedDate': { 'type':'Edm.DateTime' }, | |
'ShipperName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':40 }, | |
'ProductID': { 'key':true,'type':'Edm.Int32','nullable':false,'required':true }, | |
'ProductName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':40 }, | |
'UnitPrice': { 'key':true,'type':'Edm.Decimal','nullable':false,'required':true }, | |
'Quantity': { 'key':true,'type':'Edm.Int16','nullable':false,'required':true }, | |
'Discount': { 'key':true,'type':'Edm.Single','nullable':false,'required':true }, | |
'ExtendedPrice': { 'type':'Edm.Decimal' }, | |
'Freight': { 'type':'Edm.Decimal' } | |
}); | |
$data.Entity.extend('NorthwindModel.Order_Details_Extended', { | |
'OrderID': { 'key':true,'type':'Edm.Int32','nullable':false,'required':true }, | |
'ProductID': { 'key':true,'type':'Edm.Int32','nullable':false,'required':true }, | |
'ProductName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':40 }, | |
'UnitPrice': { 'key':true,'type':'Edm.Decimal','nullable':false,'required':true }, | |
'Quantity': { 'key':true,'type':'Edm.Int16','nullable':false,'required':true }, | |
'Discount': { 'key':true,'type':'Edm.Single','nullable':false,'required':true }, | |
'ExtendedPrice': { 'type':'Edm.Decimal' } | |
}); | |
$data.Entity.extend('NorthwindModel.Order_Subtotal', { | |
'OrderID': { 'key':true,'type':'Edm.Int32','nullable':false,'required':true }, | |
'Subtotal': { 'type':'Edm.Decimal' } | |
}); | |
$data.Entity.extend('NorthwindModel.Orders_Qry', { | |
'OrderID': { 'key':true,'type':'Edm.Int32','nullable':false,'required':true }, | |
'CustomerID': { 'type':'Edm.String','maxLength':5 }, | |
'EmployeeID': { 'type':'Edm.Int32' }, | |
'OrderDate': { 'type':'Edm.DateTime' }, | |
'RequiredDate': { 'type':'Edm.DateTime' }, | |
'ShippedDate': { 'type':'Edm.DateTime' }, | |
'ShipVia': { 'type':'Edm.Int32' }, | |
'Freight': { 'type':'Edm.Decimal' }, | |
'ShipName': { 'type':'Edm.String','maxLength':40 }, | |
'ShipAddress': { 'type':'Edm.String','maxLength':60 }, | |
'ShipCity': { 'type':'Edm.String','maxLength':15 }, | |
'ShipRegion': { 'type':'Edm.String','maxLength':15 }, | |
'ShipPostalCode': { 'type':'Edm.String','maxLength':10 }, | |
'ShipCountry': { 'type':'Edm.String','maxLength':15 }, | |
'CompanyName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':40 }, | |
'Address': { 'type':'Edm.String','maxLength':60 }, | |
'City': { 'type':'Edm.String','maxLength':15 }, | |
'Region': { 'type':'Edm.String','maxLength':15 }, | |
'PostalCode': { 'type':'Edm.String','maxLength':10 }, | |
'Country': { 'type':'Edm.String','maxLength':15 } | |
}); | |
$data.Entity.extend('NorthwindModel.Product_Sales_for_1997', { | |
'CategoryName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':15 }, | |
'ProductName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':40 }, | |
'ProductSales': { 'type':'Edm.Decimal' } | |
}); | |
$data.Entity.extend('NorthwindModel.Products_Above_Average_Price', { | |
'ProductName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':40 }, | |
'UnitPrice': { 'type':'Edm.Decimal' } | |
}); | |
$data.Entity.extend('NorthwindModel.Products_by_Category', { | |
'CategoryName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':15 }, | |
'ProductName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':40 }, | |
'QuantityPerUnit': { 'type':'Edm.String','maxLength':20 }, | |
'UnitsInStock': { 'type':'Edm.Int16' }, | |
'Discontinued': { 'key':true,'type':'Edm.Boolean','nullable':false,'required':true } | |
}); | |
$data.Entity.extend('NorthwindModel.Sales_by_Category', { | |
'CategoryID': { 'key':true,'type':'Edm.Int32','nullable':false,'required':true }, | |
'CategoryName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':15 }, | |
'ProductName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':40 }, | |
'ProductSales': { 'type':'Edm.Decimal' } | |
}); | |
$data.Entity.extend('NorthwindModel.Sales_Totals_by_Amount', { | |
'SaleAmount': { 'type':'Edm.Decimal' }, | |
'OrderID': { 'key':true,'type':'Edm.Int32','nullable':false,'required':true }, | |
'CompanyName': { 'key':true,'type':'Edm.String','nullable':false,'required':true,'maxLength':40 }, | |
'ShippedDate': { 'type':'Edm.DateTime' } | |
}); | |
$data.Entity.extend('NorthwindModel.Summary_of_Sales_by_Quarter', { | |
'ShippedDate': { 'type':'Edm.DateTime' }, | |
'OrderID': { 'key':true,'type':'Edm.Int32','nullable':false,'required':true }, | |
'Subtotal': { 'type':'Edm.Decimal' } | |
}); | |
$data.Entity.extend('NorthwindModel.Summary_of_Sales_by_Year', { | |
'ShippedDate': { 'type':'Edm.DateTime' }, | |
'OrderID': { 'key':true,'type':'Edm.Int32','nullable':false,'required':true }, | |
'Subtotal': { 'type':'Edm.Decimal' } | |
}); | |
$data.EntityContext.extend('NorthwindContext', { | |
'Categories': { type: $data.EntitySet, elementType: NorthwindModel.Category}, | |
'CustomerDemographics': { type: $data.EntitySet, elementType: NorthwindModel.CustomerDemographic}, | |
'Customers': { type: $data.EntitySet, elementType: NorthwindModel.Customer}, | |
'Employees': { type: $data.EntitySet, elementType: NorthwindModel.Employee}, | |
'Order_Details': { type: $data.EntitySet, elementType: NorthwindModel.Order_Detail}, | |
'Orders': { type: $data.EntitySet, elementType: NorthwindModel.Order}, | |
'Products': { type: $data.EntitySet, elementType: NorthwindModel.Product}, | |
'Regions': { type: $data.EntitySet, elementType: NorthwindModel.Region}, | |
'Shippers': { type: $data.EntitySet, elementType: NorthwindModel.Shipper}, | |
'Suppliers': { type: $data.EntitySet, elementType: NorthwindModel.Supplier}, | |
'Territories': { type: $data.EntitySet, elementType: NorthwindModel.Territory}, | |
'Alphabetical_list_of_products': { type: $data.EntitySet, elementType: NorthwindModel.Alphabetical_list_of_product}, | |
'Category_Sales_for_1997': { type: $data.EntitySet, elementType: NorthwindModel.Category_Sales_for_1997}, | |
'Current_Product_Lists': { type: $data.EntitySet, elementType: NorthwindModel.Current_Product_List}, | |
'Customer_and_Suppliers_by_Cities': { type: $data.EntitySet, elementType: NorthwindModel.Customer_and_Suppliers_by_City}, | |
'Invoices': { type: $data.EntitySet, elementType: NorthwindModel.Invoice}, | |
'Order_Details_Extendeds': { type: $data.EntitySet, elementType: NorthwindModel.Order_Details_Extended}, | |
'Order_Subtotals': { type: $data.EntitySet, elementType: NorthwindModel.Order_Subtotal}, | |
'Orders_Qries': { type: $data.EntitySet, elementType: NorthwindModel.Orders_Qry}, | |
'Product_Sales_for_1997': { type: $data.EntitySet, elementType: NorthwindModel.Product_Sales_for_1997}, | |
'Products_Above_Average_Prices': { type: $data.EntitySet, elementType: NorthwindModel.Products_Above_Average_Price}, | |
'Products_by_Categories': { type: $data.EntitySet, elementType: NorthwindModel.Products_by_Category}, | |
'Sales_by_Categories': { type: $data.EntitySet, elementType: NorthwindModel.Sales_by_Category}, | |
'Sales_Totals_by_Amounts': { type: $data.EntitySet, elementType: NorthwindModel.Sales_Totals_by_Amount}, | |
'Summary_of_Sales_by_Quarters': { type: $data.EntitySet, elementType: NorthwindModel.Summary_of_Sales_by_Quarter}, | |
'Summary_of_Sales_by_Years': { type: $data.EntitySet, elementType: NorthwindModel.Summary_of_Sales_by_Year} | |
}); | |
$data.generatedContexts = $data.generatedContexts || []; | |
$data.generatedContexts.push(NorthwindContext); | |
})($data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "northwind-toolkit", | |
"description": "Helps obtaining and using a local copy of the Northwind database", | |
"keywords": [ | |
"Northwind", | |
"JayData", | |
"MongoDB", | |
"OData" | |
], | |
"version": "1.0.0", | |
"homepage": "http://prantl.tk", | |
"author": { | |
"name": "Ferdinand Prantl", | |
"email": "prantl@gmail.com", | |
"url": "http://prantl.tk" | |
}, | |
"dependencies": { | |
"connect": "~2", | |
"odata-server": "*", | |
"mongodb": "*", | |
"q": "*" | |
}, | |
"repository": { | |
"type": "gist", | |
"url": "https://gist.github.com/prantlf/2afd29c30130c9beef64" | |
}, | |
"engines": { | |
"node": ">=0.8.0" | |
}, | |
"licenses": [ | |
{ | |
"type": "MIT", | |
"url": "http://jaydata.org/licensing" | |
}, | |
{ | |
"type": "GPLv2", | |
"url": "http://jaydata.org/licensing" | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Starts a HTTP server exposing a local Nothwind database | |
// at http://localhost:52999/Northwind | |
// | |
// Requires Northwind.js with the Northwind database schema and | |
// the database created by running northwind-create.js with mongodb | |
require('odata-server'); | |
require('./Northwind'); | |
$data.createODataServer({ | |
provider: { | |
name: 'mongoDB', | |
databaseName: 'Northwind' | |
}, | |
type: NorthwindContext, | |
basicAuth: function (username, password) { | |
if (username == 'admin') { | |
return password == 'admin'; | |
} else { | |
return true; | |
} | |
}, | |
checkPermission: function (access, user, entitySets, callback) { | |
if (access & $data.Access.Read) { | |
callback.success(); | |
} else if (user == 'admin') { | |
callback.success(); | |
} else { | |
callback.error('auth fail'); | |
} | |
} | |
}, '/Northwind', 52999, 'localhost'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment