Guest User

Untitled

a guest
Apr 9th, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. const Sequelize = require('sequelize');
  2.  
  3. var db;
  4. // if (!global.hasOwnProperty('db')) {
  5. // var Sequelize = require('sequelize')
  6. // , sequelize = null
  7.  
  8. if (true) {
  9. // the application is executed on Heroku ... use the postgres database
  10. db = new Sequelize('iXlGWWa9Ec','iXlGWWa9Ec' ,'XSBe9DsBF6',{
  11. port: '3306',
  12. host: 'remotemysql.com',
  13. dialect: 'mysql',
  14. pool: {
  15. min: 0,
  16. max: 5
  17. }
  18. })
  19. }
  20. // else {
  21. // // the application is executed on the local machine ... use mysql
  22. // db = new Sequelize('testdb', 'zcruz', 'zcruz', {
  23. // host: 'localhost',
  24. // dialect: 'mysql',
  25. // pool: {
  26. // min: 0,
  27. // max: 5
  28. // }
  29. // });
  30. // }
  31.  
  32. // global.db = {
  33. // Sequelize: Sequelize,
  34. // sequelize: sequelize,
  35. // User: sequelize.import(__dirname + '/user')
  36. // add your other models here
  37. // }
  38.  
  39.  
  40.  
  41. const User = db.define('users', {
  42. id: {
  43. type: Sequelize.INTEGER,
  44. primaryKey: true,
  45. autoIncrement: true,
  46. allowNull: true,
  47.  
  48. },
  49. name: {
  50. type: Sequelize.STRING,
  51. allowNull: false,
  52. },
  53. email: {
  54. type: Sequelize.STRING,
  55. allowNull: false,
  56. },
  57. address: {
  58. type: Sequelize.STRING,
  59. },
  60. phone: {
  61. type: Sequelize.STRING,
  62. },
  63. password: {
  64. type: Sequelize.STRING,
  65. allowNull: false,
  66. },
  67. blockchain:{
  68. type: Sequelize.JSON,
  69. allowNull:false
  70. },
  71. apikey:{
  72. type:Sequelize.STRING,
  73. allowNull :true
  74. },
  75. apisecret:{
  76. type:Sequelize.STRING,
  77. allowNull:true
  78. },
  79. walletname:{
  80. type:Sequelize.STRING,
  81. allowNull:true
  82. },
  83. walletpassword:{
  84. type:Sequelize.STRING,
  85. allowNull:true
  86. },
  87. walletaddress:{
  88. type:Sequelize.STRING,
  89. allowNull:true
  90. }
  91. });
  92. const Pendingtransaction = db.define('pendingtransactions',{
  93. id: {
  94. type: Sequelize.INTEGER,
  95. primaryKey: true,
  96. autoIncrement: true,
  97. allowNull: true,
  98. },
  99. transaction:{
  100. type: Sequelize.JSON,
  101. allowNull:false
  102. }
  103.  
  104. });
  105. const Listing = db.define('listings', {
  106. id: {
  107. type: Sequelize.INTEGER,
  108. primaryKey: true,
  109. autoIncrement: true,
  110. allowNull: true,
  111. },
  112.  
  113. name: {
  114. type: Sequelize.STRING,
  115. allowNull: false,
  116. },
  117. author: {
  118. type: Sequelize.STRING,
  119. },
  120. image:{
  121. type:Sequelize.STRING,
  122. },
  123. seller: {
  124. type: Sequelize.STRING,
  125. },
  126. price: {
  127. type: Sequelize.FLOAT,
  128. allowNull: false,
  129. defaultValue: 0.0,
  130. },
  131. condition: {
  132. type: Sequelize.ENUM,
  133. values: ['New', 'Almost New', 'Slight Damage', 'Worn']
  134. },
  135. // blockchain:{
  136. // type: Sequelize.JSON,
  137. // allowNull:false,
  138. // }
  139. });
  140.  
  141. Listing.belongsTo(User);
  142. const Cart = db.define('cart', {
  143. productid: {
  144. type: Sequelize.INTEGER,
  145. allowNull: false,
  146. // unique:true
  147. }
  148. });
  149. // ,{indexes: [
  150. // // Create a unique index on productid
  151. // {
  152. // unique: true,
  153. // fields: ['productid']
  154. // }]});
  155. const Wishlist = db.define('wishlist', {
  156. productid: {
  157. type: Sequelize.INTEGER,
  158. allowNull: false,
  159. // unique:true
  160. }
  161. });
  162. // ,{indexes: [
  163. // // Create a unique index on productid
  164. // {
  165. // unique: true,
  166. // fields: ['productid']
  167. // }]});
  168.  
  169. const Message = db.define('message', {
  170. sender: {
  171. type: Sequelize.STRING,
  172. allowNull: false,
  173. },
  174. product: {
  175. type: Sequelize.STRING,
  176. allowNull: false
  177. }
  178. });
  179.  
  180.  
  181. Cart.belongsTo(User);
  182. Wishlist.belongsTo(User);
  183. Message.belongsTo(User);
  184.  
  185. db.sync().then(() => {
  186. console.log("DB synced");
  187. }).catch((err) => {
  188. console.log(err.message);
  189. })
  190. exports = module.exports = {
  191. User,
  192. Listing,
  193. Cart,
  194. Wishlist,
  195. Message,
  196. Sequelize,
  197. Pendingtransaction
  198. }
Add Comment
Please, Sign In to add comment