Created
February 3, 2023 11:29
-
-
Save lesion/af0c7f1370ab6eb05cafdabd5b39ac33 to your computer and use it in GitHub Desktop.
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
const mariadb = require('mariadb') | |
const { Sequelize, DataTypes } = require('sequelize') | |
const mariadb1010conf = { host: 'localhost', port: 21103, username: 'sequelize_test', user: 'sequelize_test', password: 'sequelize_test', dialect: 'mariadb', database: 'sequelize_test'} | |
const mariadb103conf = { host: 'localhost', port: 21104, username: 'sequelize_test', user: 'sequelize_test', password: 'sequelize_test', dialect: 'mariadb', database: 'sequelize_test'} | |
async function testJSON (conn) { | |
await conn.query('USE sequelize_test') | |
// await conn.query("DROP TABLE IF EXISTS test"); | |
// await conn.query("CREATE TABLE test (value JSON)") | |
// await conn.query("INSERT INTO test values (?)", [JSON.stringify({ key: 'value' })]) | |
return conn.query('SELECT value, id FROM sequelize_tests') | |
} | |
async function testSequelizeJSON (sequelize) { | |
const Test = sequelize.define('sequelize_test', { | |
value: DataTypes.JSON | |
}) | |
// await sequelize.sync() | |
await Test.create({value: { key: 'value' }}) | |
return Test.findAll({ raw: true }) | |
} | |
async function main () { | |
let rows | |
const sequelize1010 = new Sequelize(mariadb1010conf) | |
const sequelize103 = new Sequelize(mariadb103conf) | |
const ret1010 = await testSequelizeJSON(sequelize1010) | |
console.error(ret1010) | |
const ret103 = await testSequelizeJSON(sequelize103) | |
console.error(ret103) | |
// return | |
console.error('MARIADB >= 10.5.2') | |
const mariadb1010 = await mariadb.createConnection(mariadb1010conf) | |
rows = await testJSON(mariadb1010) | |
console.error(rows) | |
console.error(typeof rows[0].value) | |
console.error('MARIADB < 10.5.2') | |
const mariadb103 = await mariadb.createConnection(mariadb103conf) | |
rows = await testJSON(mariadb103) | |
console.error(rows) | |
console.error(typeof rows[0].value) | |
} | |
main() | |
// mysqldump -u sequelize_test -P 21104 -p sequelize_test > old_db | |
// mysql -u sequelize_test -P 21103 -p sequelize_test < old_db |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment